Class: Yamori::Rest::Http
- Inherits:
-
Object
- Object
- Yamori::Rest::Http
- Defined in:
- lib/yamori/rest/http.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#instance_url ⇒ Object
readonly
Returns the value of attribute instance_url.
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(instance_url, access_token) ⇒ Http
constructor
A new instance of Http.
- #patch(path, data) ⇒ Object
- #post(path, data) ⇒ Object
Constructor Details
#initialize(instance_url, access_token) ⇒ Http
Returns a new instance of Http.
10 11 12 13 |
# File 'lib/yamori/rest/http.rb', line 10 def initialize(instance_url, access_token) @instance_url = instance_url @access_token = access_token end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
8 9 10 |
# File 'lib/yamori/rest/http.rb', line 8 def access_token @access_token end |
#instance_url ⇒ Object (readonly)
Returns the value of attribute instance_url.
8 9 10 |
# File 'lib/yamori/rest/http.rb', line 8 def instance_url @instance_url end |
Instance Method Details
#delete(path) ⇒ Object
41 42 43 44 |
# File 'lib/yamori/rest/http.rb', line 41 def delete(path) response = post_request(path + '?_HttpMethod=DELETE', '') response.code end |
#get(path) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/yamori/rest/http.rb', line 15 def get(path) url = URI.parse(instance_url + path) res = Net::HTTP.get(url, headers) if res =~/errorCode/ err = JSON.parse(res).first if err['errorCode'] == 'NOT_FOUND' raise RecordNotFoundError.new else raise RequestError.new(err['errorCode'], err['message']) end end res end |
#patch(path, data) ⇒ Object
36 37 38 39 |
# File 'lib/yamori/rest/http.rb', line 36 def patch(path, data) response = post_request(path + '?_HttpMethod=PATCH', data) response.code end |
#post(path, data) ⇒ Object
31 32 33 34 |
# File 'lib/yamori/rest/http.rb', line 31 def post(path, data) response = post_request(path, data) response.body end |