Class: Ubidots::ApiClient
- Inherits:
-
Object
- Object
- Ubidots::ApiClient
- Defined in:
- lib/ubidots.rb
Instance Method Summary collapse
- #get(endpoint) ⇒ Object
- #get_datasources ⇒ Object
- #get_variables ⇒ Object
-
#initialize(api_key = nil) ⇒ ApiClient
constructor
A new instance of ApiClient.
- #post_with_apikey(endpoint) ⇒ Object
Constructor Details
#initialize(api_key = nil) ⇒ ApiClient
Returns a new instance of ApiClient.
16 17 18 19 20 21 22 |
# File 'lib/ubidots.rb', line 16 def initialize(api_key=nil) raise "Invalid API key: #{key}" if api_key.nil? @api_key = api_key set_api_key_header get_token set_token_header end |
Instance Method Details
#get(endpoint) ⇒ Object
64 65 66 67 68 |
# File 'lib/ubidots.rb', line 64 def get(endpoint) headers = @token_header response = RestClient.get "#{Ubidots::Constants::API_URL}#{endpoint}", headers return JSON.parse(response.body) end |
#get_datasources ⇒ Object
70 71 72 73 74 |
# File 'lib/ubidots.rb', line 70 def get_datasources response = get 'datasources' raw_items = response["results"] return transform_to_datasource_objects raw_items end |
#get_variables ⇒ Object
76 77 78 79 80 |
# File 'lib/ubidots.rb', line 76 def get_variables response = get 'variables' raw_items = response["results"] return transform_to_variable_objects raw_items end |