Class: Algorithmia::Requester
- Inherits:
-
Object
- Object
- Algorithmia::Requester
- Includes:
- HTTParty
- Defined in:
- lib/algorithmia/requester.rb
Instance Method Summary collapse
- #delete(endpoint, query: {}) ⇒ Object
- #get(endpoint, query: {}, headers: {}) ⇒ Object
- #head(endpoint) ⇒ Object
-
#initialize(client) ⇒ Requester
constructor
A new instance of Requester.
- #post(endpoint, body, query: {}, headers: {}) ⇒ Object
- #put(endpoint, body, query: {}, headers: {}) ⇒ Object
Constructor Details
#initialize(client) ⇒ Requester
Returns a new instance of Requester.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/algorithmia/requester.rb', line 7 def initialize(client) self.class.base_uri client.api_address @client = client @default_headers = { 'Content-Type' => 'application/json', 'User-Agent' => 'Algorithmia Ruby Client' } unless @client.api_key.nil? @default_headers['Authorization'] = @client.api_key end end |
Instance Method Details
#delete(endpoint, query: {}) ⇒ Object
56 57 58 59 60 |
# File 'lib/algorithmia/requester.rb', line 56 def delete(endpoint, query: {}) response = self.class.delete(endpoint, query: query, headers: @default_headers) check_for_errors(response) response end |
#get(endpoint, query: {}, headers: {}) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/algorithmia/requester.rb', line 19 def get(endpoint, query: {}, headers: {}) headers = merge_headers(headers) response = self.class.get(endpoint, query: query, headers: headers) check_for_errors(response) response end |
#head(endpoint) ⇒ Object
50 51 52 53 54 |
# File 'lib/algorithmia/requester.rb', line 50 def head(endpoint) response = self.class.head(endpoint, headers: @default_headers) check_for_errors(response) response end |
#post(endpoint, body, query: {}, headers: {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/algorithmia/requester.rb', line 26 def post(endpoint, body, query: {}, headers: {}) headers = merge_headers(headers) if headers['Content-Type'] == 'application/json' body = body.to_json end response = self.class.post(endpoint, body: body, query: query, headers: headers) check_for_errors(response) response end |
#put(endpoint, body, query: {}, headers: {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/algorithmia/requester.rb', line 38 def put(endpoint, body, query: {}, headers: {}) headers = merge_headers(headers) if headers['Content-Type'] == 'application/json' body = body.to_json end response = self.class.put(endpoint, body: body, query: query, headers: headers) check_for_errors(response) response end |