Class: Atomsphere::Api::Client
- Inherits:
-
Object
- Object
- Atomsphere::Api::Client
- Defined in:
- lib/atomsphere/api/client.rb
Instance Method Summary collapse
- #bulk_get(path, ids) ⇒ Object
- #get(path) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #post(path, data) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/atomsphere/api/client.rb', line 9 def initialize validate! end |
Instance Method Details
#bulk_get(path, ids) ⇒ Object
35 36 37 38 39 |
# File 'lib/atomsphere/api/client.rb', line 35 def bulk_get path, ids request = { type: 'GET', request: ids.map{ |id| {id: id} } } path = [*path] << :bulk post path, request end |
#get(path) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/atomsphere/api/client.rb', line 26 def get path header = {'Accept' => 'application/json'} request = Net::HTTP::Get.new api_uri(path), header request.basic_auth config.username, config.password http_request request end |
#post(path, data) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/atomsphere/api/client.rb', line 13 def post path, data header = { 'Content-Type' => 'application/json', 'Accept' => ' application/json' } request = Net::HTTP::Post.new api_uri(path), header request.body = (String === data ? data : data.to_json) request.basic_auth config.username, config.password http_request request end |