Class: Ubr::API
- Inherits:
-
Object
- Object
- Ubr::API
- Defined in:
- lib/ubr/api.rb
Class Method Summary collapse
- .authorize(client_id:, code:, secret:, redirect_uri:) ⇒ Object
- .parse_response(response) ⇒ Object
- .token_path ⇒ Object
Instance Method Summary collapse
- #get(path, params = {}) ⇒ Object
-
#initialize ⇒ API
constructor
A new instance of API.
- #parse_response(response) ⇒ Object
- #post(path, params = {}) ⇒ Object
Constructor Details
#initialize ⇒ API
Returns a new instance of API.
7 8 9 10 11 12 13 14 15 |
# File 'lib/ubr/api.rb', line 7 def initialize token = File.read(API.token_path).strip @client = RestClient::Resource.new('https://api.uber.com/v1', headers: { authorization: "Bearer #{token}", content_type: 'application/json' } ) end |
Class Method Details
.authorize(client_id:, code:, secret:, redirect_uri:) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ubr/api.rb', line 28 def self.(client_id:, code:, secret:, redirect_uri:) client = RestClient::Resource.new('https://login.uber.com/oauth/token') parse_response client.post( client_secret: secret, client_id: client_id, grant_type: 'authorization_code', redirect_uri: redirect_uri, code: code, ) end |
.parse_response(response) ⇒ Object
25 26 27 |
# File 'lib/ubr/api.rb', line 25 def self.parse_response(response) JSON.parse response, symbolize_names: true end |
.token_path ⇒ Object
38 39 40 |
# File 'lib/ubr/api.rb', line 38 def self.token_path File.('~/.ubr') end |
Instance Method Details
#get(path, params = {}) ⇒ Object
16 17 18 |
# File 'lib/ubr/api.rb', line 16 def get(path, params={}) parse_response @client[path].get(params: params) end |
#parse_response(response) ⇒ Object
22 23 24 |
# File 'lib/ubr/api.rb', line 22 def parse_response(response) API.parse_response(response) end |
#post(path, params = {}) ⇒ Object
19 20 21 |
# File 'lib/ubr/api.rb', line 19 def post(path, params={}) parse_response @client[path].post(params.to_json) end |