Class: Mirrorhub::API::Client
- Inherits:
-
Object
- Object
- Mirrorhub::API::Client
- Defined in:
- lib/mirrorhub/api/client.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #auth ⇒ Object
- #get(resource, params: {}, headers: {}) ⇒ Object
-
#initialize(location) ⇒ Client
constructor
A new instance of Client.
- #post(resource, params: {}, headers: {}, body: {}) ⇒ Object
Constructor Details
#initialize(location) ⇒ Client
8 9 10 |
# File 'lib/mirrorhub/api/client.rb', line 8 def initialize(location) @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
6 7 8 |
# File 'lib/mirrorhub/api/client.rb', line 6 def location @location end |
#token ⇒ Object
Returns the value of attribute token.
7 8 9 |
# File 'lib/mirrorhub/api/client.rb', line 7 def token @token end |
Instance Method Details
#auth ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/mirrorhub/api/client.rb', line 12 def auth res = post('contacts/auth', headers: {'Grpc-Metadata-ContactEmail': mail, 'Grpc-Metadata-ContactPassword': password}) true if @token = res['token'] end |
#get(resource, params: {}, headers: {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mirrorhub/api/client.rb', line 20 def get(resource, params: {}, headers: {}) request = Typhoeus::Request.new( "#{@location}/#{resource}", method: :get, params: params, headers: headers ) res = request.run JSON.parse(res.response_body) end |
#post(resource, params: {}, headers: {}, body: {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mirrorhub/api/client.rb', line 31 def post(resource, params: {}, headers: {}, body: {}) request = Typhoeus::Request.new( "#{@location}/#{resource}", method: :post, params: params, body: body.to_json, headers: headers ) res = request.run JSON.parse(res.response_body) end |