ubidots 0.0.1 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/README.rst +148 -0
- data/lib/ubidots.rb +25 -59
- data/lib/ubidots/datasource.rb +12 -9
- data/lib/ubidots/server_bridge.rb +87 -0
- data/lib/ubidots/variable.rb +35 -4
- data/lib/ubidots/version.rb +1 -1
- data/ubidots.gemspec +8 -7
- metadata +27 -27
- data/README.md +0 -86
- data/lib/ubidots/datasource_service.rb +0 -17
- data/lib/ubidots/user.rb +0 -29
- data/lib/ubidots/user_service.rb +0 -9
- data/lib/ubidots/variable_service.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OTY3OWMyNzA1NGU0YWUyZjg3MWI3ZjM0NGNjMWM1ZWViM2VhODJlZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NjU1YjU5ZmM5YThmNDNjNzVjZWZkZjEyYTk4YWJiYTY2NTlhNjIyNA==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTU0OTRjY2UwNTIzYzAxNTQ3MGI0ZjJjMGIyZjlmNjQwZTRmYzlhZjM3YWQ5
|
10
|
+
YzcyNDBlYWZjZjBiZTAzMzliNjJiOGY5NmQ5OWRiYzUyODIxMTYzYmVmMDJh
|
11
|
+
MGVkOWJhMDQ1ZWYxZGMxOWZmMTgwNTY4ODgzOWU5NzdhZmFkOWY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTk2MjE3NDllNzU1MmYxNGMzZGEwZjVkZDEzMDZlNmJjYWM4ZDE0N2ZlNjJl
|
14
|
+
NzUyYzg1NzY0Yzk4NWY3MTM2NmFmNmNmMzA2NjIxODgyZjEwNTc2M2YzOThh
|
15
|
+
Yjg5OTVmNmNjZDllZjBkNjNhMzI2YTQ1MDQ5NTYzMWZhYzdhMjQ=
|
data/README.rst
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
===================================
|
2
|
+
Ubidots Ruby API Client
|
3
|
+
===================================
|
4
|
+
|
5
|
+
The Ubidots Ruby API Client makes calls to the `Ubidots Api <http://things.ubidots.com/api>`_.
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:.
|
11
|
+
|
12
|
+
.. code-block:: ruby
|
13
|
+
|
14
|
+
gem 'ubidots'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
.. code-block:: bash
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
.. code-block:: bash
|
25
|
+
|
26
|
+
$ gem install ubidots
|
27
|
+
|
28
|
+
|
29
|
+
Connecting to the API
|
30
|
+
----------------------
|
31
|
+
|
32
|
+
Before playing with the API you should connect to it using your private API key, which can be found `in your profile <http://app.ubidots.com/userdata/api/>`_.
|
33
|
+
|
34
|
+
If you don't have an account yet, you can `create one here <http://app.ubidots.com/accounts/signup/>`_.
|
35
|
+
|
36
|
+
Once you have your API key, you can connect to the API by creating an ApiClient instance. Let's assume your API key is: "7fj39fk3044045k89fbh34rsd9823jkfs8323". Then your code would look like this:
|
37
|
+
|
38
|
+
|
39
|
+
.. code-block:: ruby
|
40
|
+
|
41
|
+
require 'ubidots'
|
42
|
+
|
43
|
+
@api = Ubidots::ApiClient.new("7fj39fk3044045k89fbh34rsd9823jkfs8323")
|
44
|
+
|
45
|
+
|
46
|
+
Now you have an instance of ApiClient ("api") which can be used to connect to the Ubidots API.
|
47
|
+
|
48
|
+
Saving a new Value to a Variable
|
49
|
+
--------------------------------
|
50
|
+
|
51
|
+
Retrieve the variable you'd like the value to be saved to:
|
52
|
+
|
53
|
+
.. code-block:: ruby
|
54
|
+
|
55
|
+
my_variable = @api.get_variable('56799cf1231b28459f976417')
|
56
|
+
|
57
|
+
Given the instantiated variable, you can save a new value with the following line:
|
58
|
+
|
59
|
+
.. code-block:: ruby
|
60
|
+
|
61
|
+
new_value = my_variable.save_value( {'value'=>10} )
|
62
|
+
|
63
|
+
You can also specify a timestamp (optional):
|
64
|
+
|
65
|
+
.. code-block:: ruby
|
66
|
+
|
67
|
+
new_value = my_variable.save_value( {'value'=>10, 'timestamp'=>1376061804407} )
|
68
|
+
|
69
|
+
If no timestamp is specified, the API server will assign the current time to it. We think it's always better for you to specify the timestamp so the record reflects the exact time the value was captured, not the time it arrived to our servers.
|
70
|
+
|
71
|
+
Creating a Data Source
|
72
|
+
----------------------
|
73
|
+
|
74
|
+
As you might know by now, a data source represents a device that's generating time-series data.
|
75
|
+
|
76
|
+
This line creates a new data source:
|
77
|
+
|
78
|
+
.. code-block:: ruby
|
79
|
+
|
80
|
+
new_datasource = @api.create_datasource( {"name"=>"myNewDs", "tags"=>["firstDs", "new"], "description"=>"any des"} )
|
81
|
+
|
82
|
+
The 'name' key is required, but the 'tags' and 'description' keys are optional. This new data source can be used to track different variables, so let's create one.
|
83
|
+
|
84
|
+
|
85
|
+
Creating a Variable
|
86
|
+
--------------------
|
87
|
+
|
88
|
+
A variable is a time-series containing different values over time. Let's create one:
|
89
|
+
|
90
|
+
|
91
|
+
.. code-block:: ruby
|
92
|
+
|
93
|
+
new_variable = new_datasource.create_variable( {"name"=>"myNewVar", "unit"=>"Nw"} )
|
94
|
+
|
95
|
+
The 'name' and 'unit' keys are required.
|
96
|
+
|
97
|
+
Getting Values
|
98
|
+
--------------
|
99
|
+
|
100
|
+
To get the values of a variable, use the method get_values in an instance of the class Variable. This will return a values array.
|
101
|
+
|
102
|
+
If you only want the last N values call the method with the number of elements you want.
|
103
|
+
|
104
|
+
.. code-block:: ruby
|
105
|
+
|
106
|
+
all_values = my_variable.get_values()
|
107
|
+
|
108
|
+
|
109
|
+
Getting a group of Data Sources
|
110
|
+
--------------------------------
|
111
|
+
|
112
|
+
If you want to get all your data sources you can a method on the ApiClient instance directly. This method return a objects Datasource array.
|
113
|
+
|
114
|
+
.. code-block:: ruby
|
115
|
+
|
116
|
+
all_datasources = @api.get_datasources()
|
117
|
+
|
118
|
+
|
119
|
+
Getting a specific Data source
|
120
|
+
-------------------------------
|
121
|
+
|
122
|
+
Each data source is identified by an ID. A specific data source can be retrieved from the server using this ID.
|
123
|
+
|
124
|
+
For example, if a data source has the id 51c99cfdf91b28459f976414, it can be retrieved as follows:
|
125
|
+
|
126
|
+
|
127
|
+
.. code-block:: ruby
|
128
|
+
|
129
|
+
my_specific_datasource = @api.get_datasource('51c99cfdf91b28459f976414')
|
130
|
+
|
131
|
+
Getting a group of Variables from a Data source
|
132
|
+
-------------------------------------------------
|
133
|
+
|
134
|
+
You can also retrieve some or all of the variables of a data source:
|
135
|
+
|
136
|
+
.. code-block:: ruby
|
137
|
+
|
138
|
+
all_variables_of_datasource = my_datasource.get_variables()
|
139
|
+
|
140
|
+
|
141
|
+
Getting a specific Variable
|
142
|
+
------------------------------
|
143
|
+
|
144
|
+
As with data sources, you can use your variable's ID to retrieve the details about it:
|
145
|
+
|
146
|
+
.. code-block:: ruby
|
147
|
+
|
148
|
+
my_specific_variable = @api.get_variable('56799cf1231b28459f976417')
|
data/lib/ubidots.rb
CHANGED
@@ -2,87 +2,53 @@ require "rest_client"
|
|
2
2
|
require "json"
|
3
3
|
require "ubidots/version"
|
4
4
|
require "ubidots/constants"
|
5
|
-
require "ubidots/user"
|
6
5
|
require "ubidots/variable"
|
7
6
|
require "ubidots/datasource"
|
8
|
-
require "ubidots/
|
9
|
-
require "ubidots/util/array"
|
7
|
+
require "ubidots/server_bridge"
|
10
8
|
|
11
9
|
module Ubidots
|
12
10
|
include Constants
|
13
11
|
|
14
12
|
class ApiClient
|
15
13
|
|
16
|
-
def initialize(api_key=nil)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
set_token_header
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def get_token
|
27
|
-
endpoint = "auth/token/"
|
28
|
-
response = post_with_apikey endpoint
|
29
|
-
@token = response['token']
|
30
|
-
end
|
31
|
-
|
32
|
-
def set_api_key_header
|
33
|
-
@apikey_header = { 'X-UBIDOTS-APIKEY' => @api_key }
|
34
|
-
end
|
35
|
-
|
36
|
-
def set_token_header
|
37
|
-
@token_header = { 'X-AUTH-TOKEN' => @token }
|
38
|
-
end
|
39
|
-
|
40
|
-
def transform_to_datasource_objects(raw_items)
|
41
|
-
datasources = []
|
42
|
-
raw_items.each_with_index do |raw_item, i|
|
43
|
-
datasources[i] = Ubidots::Datasource.new(raw_item)
|
14
|
+
def initialize(api_key=nil, token=nil, base_url=nil, bridge=nil)
|
15
|
+
if bridge
|
16
|
+
@bridge = bridge
|
17
|
+
else
|
18
|
+
@bridge = Ubidots::ServerBridge.new(api_key, token, base_url)
|
44
19
|
end
|
45
|
-
return datasources
|
46
|
-
end
|
47
|
-
|
48
|
-
def transform_to_variable_objects(raw_items)
|
49
|
-
variables = []
|
50
|
-
raw_items.each_with_index do |raw_item, i|
|
51
|
-
variables[i] = Ubidots::Variable.new(raw_item)
|
52
|
-
end
|
53
|
-
return variables
|
54
20
|
end
|
55
21
|
|
56
22
|
public
|
57
23
|
|
58
|
-
def post_with_apikey(endpoint)
|
59
|
-
headers = @apikey_header
|
60
|
-
response = RestClient.post "#{Ubidots::Constants::API_URL}#{endpoint}", {}, headers
|
61
|
-
return JSON.parse(response.body)
|
62
|
-
end
|
63
|
-
|
64
|
-
def get(endpoint)
|
65
|
-
headers = @token_header
|
66
|
-
response = RestClient.get "#{Ubidots::Constants::API_URL}#{endpoint}", headers
|
67
|
-
return JSON.parse(response.body)
|
68
|
-
end
|
69
|
-
|
70
24
|
def get_datasources
|
71
|
-
response = get 'datasources'
|
25
|
+
response = @bridge.get 'datasources'
|
72
26
|
raw_items = response["results"]
|
73
|
-
return transform_to_datasource_objects raw_items
|
27
|
+
return @bridge.transform_to_datasource_objects raw_items
|
74
28
|
end
|
75
29
|
|
76
30
|
def get_variables
|
77
|
-
response = get 'variables'
|
31
|
+
response = @bridge.get 'variables'
|
78
32
|
raw_items = response["results"]
|
79
|
-
return transform_to_variable_objects raw_items
|
33
|
+
return @bridge.transform_to_variable_objects raw_items
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_datasource(id=nil)
|
37
|
+
endpoint = "datasources/#{id}"
|
38
|
+
response = @bridge.get endpoint
|
39
|
+
return Ubidots::Datasource.new(@bridge, response)
|
80
40
|
end
|
81
41
|
|
82
|
-
|
42
|
+
def create_datasource(data)
|
43
|
+
endpoint = "datasources";
|
44
|
+
response = @bridge.post endpoint, data
|
45
|
+
return Ubidots::Datasource.new(@bridge, response)
|
46
|
+
end
|
83
47
|
|
84
|
-
def
|
85
|
-
|
48
|
+
def get_variable(id=nil)
|
49
|
+
endpoint = "variables/#{id}"
|
50
|
+
response = @bridge.get endpoint
|
51
|
+
return Ubidots::Variable.new(@bridge, response)
|
86
52
|
end
|
87
53
|
|
88
54
|
end
|
data/lib/ubidots/datasource.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'ubidots/datasource_service'
|
2
1
|
module Ubidots
|
3
2
|
class Datasource
|
4
3
|
|
5
4
|
attr_reader :id, :name, :url, :last_activity, :tags, :description, :created_at
|
6
5
|
attr_reader :owner, :parent, :context, :variables_url, :number_of_variables
|
7
6
|
|
8
|
-
def initialize(data)
|
7
|
+
def initialize(bridge, data)
|
8
|
+
@bridge = bridge
|
9
9
|
@id = data["id"]
|
10
10
|
@name = data["name"]
|
11
11
|
@url = data["url"]
|
@@ -22,18 +22,21 @@ module Ubidots
|
|
22
22
|
|
23
23
|
def get_variables
|
24
24
|
endpoint = "datasources/#{@id}/variables"
|
25
|
-
response =
|
25
|
+
response = @bridge.get endpoint
|
26
26
|
raw_items = response["results"]
|
27
|
-
return
|
27
|
+
return @bridge.transform_to_variable_objects raw_items
|
28
28
|
end
|
29
|
-
|
30
29
|
|
31
|
-
def
|
32
|
-
|
30
|
+
def remove_datasource
|
31
|
+
endpoint = "datasources/#{@id}";
|
32
|
+
@bridge.delete endpoint
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
|
35
|
+
def create_variable(data)
|
36
|
+
endpoint = "datasources/#{@id}/variables"
|
37
|
+
response = @bridge.post endpoint, data
|
38
|
+
return Ubidots::Variable.new(@bridge, response)
|
37
39
|
end
|
40
|
+
|
38
41
|
end
|
39
42
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Ubidots
|
2
|
+
class ServerBridge
|
3
|
+
|
4
|
+
def initialize(api_key=nil, token=nil, base_url=nil)
|
5
|
+
@base_url = base_url ? base_url : Ubidots::Constants::API_URL
|
6
|
+
if api_key
|
7
|
+
@api_key = api_key
|
8
|
+
set_api_key_header
|
9
|
+
get_token
|
10
|
+
set_token_header
|
11
|
+
elsif token
|
12
|
+
@api_key = nil
|
13
|
+
@token = token
|
14
|
+
set_token_header
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def get_token
|
21
|
+
endpoint = "auth/token/"
|
22
|
+
response = post_with_apikey endpoint
|
23
|
+
@token = response['token']
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_api_key_header
|
27
|
+
@apikey_header = { 'X-UBIDOTS-APIKEY' => @api_key }
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_token_header
|
31
|
+
@token_header = { 'X-AUTH-TOKEN' => @token }
|
32
|
+
end
|
33
|
+
|
34
|
+
def prepare_data(data)
|
35
|
+
return data
|
36
|
+
end
|
37
|
+
|
38
|
+
public
|
39
|
+
|
40
|
+
def transform_to_datasource_objects(raw_items)
|
41
|
+
datasources = []
|
42
|
+
raw_items.each_with_index do |raw_item, i|
|
43
|
+
datasources[i] = Ubidots::Datasource.new(self, raw_item)
|
44
|
+
end
|
45
|
+
return datasources
|
46
|
+
end
|
47
|
+
|
48
|
+
def transform_to_variable_objects(raw_items)
|
49
|
+
variables = []
|
50
|
+
raw_items.each_with_index do |raw_item, i|
|
51
|
+
variables[i] = Ubidots::Variable.new(self, raw_item)
|
52
|
+
end
|
53
|
+
return variables
|
54
|
+
end
|
55
|
+
|
56
|
+
def post_with_apikey(endpoint)
|
57
|
+
headers = @apikey_header
|
58
|
+
response = RestClient.post "#{@base_url}#{endpoint}", {}, headers
|
59
|
+
return JSON.parse(response.body)
|
60
|
+
end
|
61
|
+
|
62
|
+
def get(endpoint)
|
63
|
+
headers = @token_header
|
64
|
+
response = RestClient.get "#{@base_url}#{endpoint}", headers
|
65
|
+
return JSON.parse(response.body)
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_with_url(url)
|
69
|
+
headers = @token_header
|
70
|
+
response = RestClient.get url, headers
|
71
|
+
return JSON.parse(response.body)
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def post(endpoint, data)
|
76
|
+
headers = @token_header
|
77
|
+
data = prepare_data(data)
|
78
|
+
response = RestClient.post "#{@base_url}#{endpoint}", data, headers
|
79
|
+
return JSON.parse(response.body)
|
80
|
+
end
|
81
|
+
|
82
|
+
def delete(endpoint)
|
83
|
+
headers = @token_header
|
84
|
+
RestClient.delete "#{@base_url}#{endpoint}", headers
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/ubidots/variable.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
require 'ubidots/variable_service'
|
2
|
-
|
3
1
|
module Ubidots
|
4
2
|
class Variable
|
5
3
|
|
6
4
|
attr_reader :id, :name, :url, :last_activity, :tags, :description, :created_at
|
7
5
|
attr_reader :icon, :unit, :raw_datasource, :properties, :values_url, :last_value
|
8
6
|
|
9
|
-
def initialize(data)
|
7
|
+
def initialize(bridge, data)
|
8
|
+
@bridge = bridge
|
10
9
|
@id = data["id"]
|
11
10
|
@name = data["name"]
|
12
11
|
@url = data["url"]
|
@@ -22,6 +21,38 @@ module Ubidots
|
|
22
21
|
@last_value = data["last_value"]
|
23
22
|
end
|
24
23
|
|
25
|
-
|
24
|
+
def get_values
|
25
|
+
endpoint = "variables/#{@id}/values"
|
26
|
+
response = @bridge.get endpoint
|
27
|
+
return response["results"]
|
28
|
+
end
|
29
|
+
|
30
|
+
def save_value(data)
|
31
|
+
endpoint = "variables/#{@id}/values"
|
32
|
+
return @bridge.post endpoint, data
|
33
|
+
end
|
26
34
|
|
35
|
+
def save_values(data, force=false)
|
36
|
+
endpoint = "variables/#{@id}/values"
|
37
|
+
if force == true
|
38
|
+
endpoint = "#{endpoint}?force=true"
|
39
|
+
end
|
40
|
+
return @bridge.post endpoint, data
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove_variable
|
44
|
+
endpoint = "variables/#{@id}"
|
45
|
+
return @bridge.delete endpoint
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_datasource
|
49
|
+
if !@datasource
|
50
|
+
datasource_id = @raw_datasource["id"]
|
51
|
+
endpoint = "datasources/#{datasource_id}"
|
52
|
+
response = @bridge.get endpoint
|
53
|
+
@datasource = Ubidots::Datasource.new(@bridge, response)
|
54
|
+
end
|
55
|
+
return @datasource
|
56
|
+
end
|
57
|
+
end
|
27
58
|
end
|
data/lib/ubidots/version.rb
CHANGED
data/ubidots.gemspec
CHANGED
@@ -6,18 +6,19 @@ require 'ubidots/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "ubidots"
|
8
8
|
gem.version = Ubidots::VERSION
|
9
|
-
gem.authors = ["Federico Builes"]
|
10
|
-
gem.email = ["federico.builes@gmail.com"]
|
11
|
-
gem.description = "Ruby library
|
9
|
+
gem.authors = ["Federico Builes", "Julián Hernandez"]
|
10
|
+
gem.email = ["federico.builes@gmail.com", "julian@ubidots.com"]
|
11
|
+
gem.description = "Official Ruby library for the Ubidots API"
|
12
12
|
gem.summary = "Ruby library to access the Ubidots API"
|
13
|
-
gem.homepage = ""
|
13
|
+
gem.homepage = "http://ubidots.com"
|
14
|
+
gem.licenses = ['MIT']
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($/)
|
16
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
19
|
gem.require_paths = ["lib"]
|
19
20
|
|
20
|
-
gem.add_dependency
|
21
|
-
gem.add_dependency
|
22
|
-
gem.add_development_dependency
|
21
|
+
gem.add_dependency "rest-client", "~> 1.6"
|
22
|
+
gem.add_dependency "json", "~> 1.8"
|
23
|
+
gem.add_development_dependency "rspec", "~> 2.14"
|
23
24
|
end
|
metadata
CHANGED
@@ -1,81 +1,80 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ubidots
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Builes
|
8
|
+
- Julián Hernandez
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rest-client
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- -
|
18
|
+
- - ~>
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
+
version: '1.6'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
|
-
- -
|
25
|
+
- - ~>
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
+
version: '1.6'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: json
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- -
|
32
|
+
- - ~>
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
+
version: '1.8'
|
34
35
|
type: :runtime
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- -
|
39
|
+
- - ~>
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
+
version: '1.8'
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
43
|
name: rspec
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
|
-
- -
|
46
|
+
- - ~>
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
+
version: '2.14'
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
|
-
- -
|
53
|
+
- - ~>
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
description: Ruby library
|
55
|
+
version: '2.14'
|
56
|
+
description: Official Ruby library for the Ubidots API
|
56
57
|
email:
|
57
58
|
- federico.builes@gmail.com
|
59
|
+
- julian@ubidots.com
|
58
60
|
executables: []
|
59
61
|
extensions: []
|
60
62
|
extra_rdoc_files: []
|
61
63
|
files:
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
64
|
+
- .gitignore
|
65
|
+
- .rspec
|
66
|
+
- .rvmrc
|
65
67
|
- Gemfile
|
66
68
|
- LICENSE.txt
|
67
|
-
- README.
|
69
|
+
- README.rst
|
68
70
|
- Rakefile
|
69
71
|
- lib/ubidots.rb
|
70
72
|
- lib/ubidots/constants.rb
|
71
73
|
- lib/ubidots/datasource.rb
|
72
|
-
- lib/ubidots/
|
73
|
-
- lib/ubidots/user.rb
|
74
|
-
- lib/ubidots/user_service.rb
|
74
|
+
- lib/ubidots/server_bridge.rb
|
75
75
|
- lib/ubidots/util/array.rb
|
76
76
|
- lib/ubidots/util/collection_with_finders.rb
|
77
77
|
- lib/ubidots/variable.rb
|
78
|
-
- lib/ubidots/variable_service.rb
|
79
78
|
- lib/ubidots/version.rb
|
80
79
|
- spec/collection_with_finders_spec.rb
|
81
80
|
- spec/datasource_spec.rb
|
@@ -83,8 +82,9 @@ files:
|
|
83
82
|
- spec/ubidots_spec.rb
|
84
83
|
- spec/user_spec.rb
|
85
84
|
- ubidots.gemspec
|
86
|
-
homepage:
|
87
|
-
licenses:
|
85
|
+
homepage: http://ubidots.com
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
88
|
metadata: {}
|
89
89
|
post_install_message:
|
90
90
|
rdoc_options: []
|
@@ -92,12 +92,12 @@ require_paths:
|
|
92
92
|
- lib
|
93
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - ! '>='
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- -
|
100
|
+
- - ! '>='
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
data/README.md
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
# Ubidots
|
2
|
-
|
3
|
-
Ruby gem for connecting to the [Ubidots](http://ubidots.com) API.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'ubidots'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install ubidots
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
### Getting an API token
|
22
|
-
|
23
|
-
The first thing you need to do to start using the API is to get a token. For this you'll need to
|
24
|
-
obtain your account API key on the website and then call `Ubidots.api_key`:
|
25
|
-
|
26
|
-
Ubidots.api_key("458cacdd594246daf5126bf106ccaaefabf1bf56")
|
27
|
-
|
28
|
-
|
29
|
-
### Users
|
30
|
-
|
31
|
-
After getting your application token you can get a user object by calling:
|
32
|
-
|
33
|
-
user = Ubidots::User.find("username")
|
34
|
-
|
35
|
-
This user has an associated set of datasources that you can retrieve like this:
|
36
|
-
|
37
|
-
user = Ubidots::User.find("username")
|
38
|
-
user.datasources # => [...]
|
39
|
-
|
40
|
-
#### Profiles
|
41
|
-
|
42
|
-
You can see the user's profile by calling `#profile` on your user object:
|
43
|
-
|
44
|
-
user = Ubidots::User.find("username")
|
45
|
-
user.profile # => { followers: 11, following: 24...}
|
46
|
-
|
47
|
-
### Data Sources
|
48
|
-
|
49
|
-
The datasources for the logged in user can be retrieved by doing:
|
50
|
-
|
51
|
-
Ubidots.datasources
|
52
|
-
|
53
|
-
For a specific datasources you can pass the `datasource_id` to the `#find` method:
|
54
|
-
|
55
|
-
source = Ubidots.datasources.find(datsource_id)
|
56
|
-
|
57
|
-
And you can read the variables from this datsources:
|
58
|
-
|
59
|
-
source = Ubidots.datasources.find(datsource_id)
|
60
|
-
variables = source.variables
|
61
|
-
|
62
|
-
### Variables
|
63
|
-
|
64
|
-
To obtain a list of the variables associated to the current user you can call:
|
65
|
-
|
66
|
-
Ubidots.variables
|
67
|
-
|
68
|
-
For a specific variable just call `#find` on the variables collection and pass it the `variable_id`:
|
69
|
-
|
70
|
-
Ubidots.variables.find(variable_id)
|
71
|
-
|
72
|
-
#### Values
|
73
|
-
|
74
|
-
Each variable has a list of values. To obtain these just call `#values` on the specific variable:
|
75
|
-
|
76
|
-
variable = Ubidots.variables.find(variable_id)
|
77
|
-
values = variable.values
|
78
|
-
|
79
|
-
You can get specific information about each value by passing a `value_id`:
|
80
|
-
|
81
|
-
values = Ubidots.variables.find(variable_id).values
|
82
|
-
value = values.find(value_id)
|
83
|
-
|
84
|
-
|
85
|
-
### Error Handling
|
86
|
-
### Query parameters
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'ubidots/datasource'
|
2
|
-
|
3
|
-
module Ubidots
|
4
|
-
class DatasourceService
|
5
|
-
def self.retrieve(username)
|
6
|
-
url = "#{Ubidots::API_URL}/users/#{username}/datasources/"
|
7
|
-
response = RestClient.get url, { "X-UbidotsApiKey" => @@key }
|
8
|
-
JSON.parse(response.body).to_collection_with_finders
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.retrieve_without_username
|
12
|
-
url = "#{Ubidots::API_URL}/users/datasources/"
|
13
|
-
response = RestClient.get url, Ubidots::default_headers
|
14
|
-
JSON.parse(response.body).to_collection_with_finders
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/ubidots/user.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'ubidots/user_service'
|
2
|
-
|
3
|
-
module Ubidots
|
4
|
-
class User
|
5
|
-
attr_reader :datasources, :variables, :followers, :following
|
6
|
-
attr_reader :created_at, :blog, :username, :profile
|
7
|
-
|
8
|
-
def initialize(params={})
|
9
|
-
@profile = params
|
10
|
-
@profile.each do |key, value|
|
11
|
-
instance_variable_set("@#{key}", value)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.find(username)
|
16
|
-
data = UserService.retrieve(username)
|
17
|
-
return nil if data.nil?
|
18
|
-
User.new(data.merge( username: username ))
|
19
|
-
end
|
20
|
-
|
21
|
-
def datasources
|
22
|
-
DatasourceService.retrieve(username).to_collection_with_finders
|
23
|
-
end
|
24
|
-
|
25
|
-
def primary_key
|
26
|
-
username
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/lib/ubidots/user_service.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module Ubidots
|
2
|
-
class VariableService
|
3
|
-
def self.retrieve_from_datasource(source)
|
4
|
-
url = "#{Ubidots::API_URL}/datasources/#{source.primary_key}/variables/"
|
5
|
-
response = RestClient.get url, { "X-UbidotsApiKey" => @@key }
|
6
|
-
JSON.parse(response.body).to_collection_with_finders
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.retrieve_for_current_user
|
10
|
-
url = "#{Ubidots::API_URL}/variables/"
|
11
|
-
response = RestClient.get url, { "X-UbidotsApiKey" => @@key }
|
12
|
-
JSON.parse(response.body).to_collection_with_finders
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|