leftronicapi 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +20 -13
  2. data/Rakefile +2 -1
  3. data/leftronicapi.gemspec +11 -10
  4. data/lib/leftronic.rb +68 -72
  5. metadata +39 -56
data/README.md CHANGED
@@ -59,7 +59,7 @@ require 'leftronic'
59
59
  Create a class instance with your API key. Feel free to name it whatever you'd like.
60
60
 
61
61
  ```ruby
62
- update = Leftronic.new("YOUR_ACCESS_KEY")
62
+ leftronic = Leftronic.new "YOUR_ACCESS_KEY"
63
63
  ```
64
64
 
65
65
  Here are some example functions to push to your dashboard. Be sure you have configured the correct widgets to accept custom data points. Also, be sure that you have entered your API access key correctly.
@@ -67,35 +67,42 @@ Here are some example functions to push to your dashboard. Be sure you have conf
67
67
  Let's start with pushing a number to a widget.
68
68
 
69
69
  ```ruby
70
- update = Leftronic.pushNumber("yourNumberStream", 14600)
70
+ update = leftronic.push_number "yourNumberStream", 14600
71
71
  ```
72
72
 
73
- Now we'll push some geographic coordinates to a map widget. You can use either the U.S. or world map widgets. The first coordinate (37.8) is the latitude and the second coordinate (-122.6) is the longitude. If your request is successful, you should see a data point appear on San Francisco, California.
73
+ Now we'll push some geographic coordinates to a map widget. You can use either the U.S. or world map widgets. The first coordinate (37.8) is the latitude and the second coordinate (-122.6) is the longitude. If your request is successful, you should see a data point appear on San Francisco, California. Optionally, if you'd like to set the color of your map point simply specify that in your function call. *Note*: only red, blue, green, purple, and yellow colors are supported at this time. Incorrect or missing color will default to red.
74
74
 
75
75
  ```ruby
76
- update = Leftronic.pushGeo("yourGeoStream", 37.8, -122.6)
76
+ update = leftronic.push_geo "yourGeoStream", 37.8, -122.6
77
+ ```
78
+
79
+ ```ruby
80
+ update = leftronic.push_geo "yourGeoStream", 37.8, -122.6, :blue
77
81
  ```
78
82
 
79
83
  Here's how you push a title and message to a text feed widget.
80
84
 
81
85
  ```ruby
82
- update = Leftronic.pushText("yourTextStream", "This is my title.", "Hello World!")
86
+ update = leftronic.push_text "yourTextStream", "This is my title.", "Hello World!"
83
87
  ```
84
88
 
85
- Let's push an array of names and values to a leaderboard widget. Be sure to create the array first (you may call it whatever you'd like). Be careful to use the proper syntax. Next, push the array to your widget.
89
+ A leaderboard widget requires a hash. The widget will display the hash entries sorted by value.
86
90
 
87
91
  ```ruby
88
- leaderArray = Array[{"name" => "Johnny", "value" => 84}, {"name" => "Jamie", "value" => 75}, {"name" => "Lance", "value" => 62}]
89
-
90
- update = Leftronic.pushLeaderboard("yourBoardStream", leaderArray)
92
+ update = leftronic.push_leaderboard "yourBoardStream", some_hash
93
+ ```
94
+ ```ruby
95
+ update = leftronic.push_leaderboard "yourBoardStream", 'Johnny' => 84, 'Jamie' => 75, 'Lance' => 62
91
96
  ```
92
97
 
93
- Similar to the last example, let's push a list of items to a list widget. Same rules as last time.
98
+ Finally, let's push an array to a list widget.
94
99
 
95
100
  ```ruby
96
- listArray = Array[{"listItem" => "Elizabeth"}, {"listItem" => "Marshall"}, {"listItem" => "Claire"}, {"listItem" => "Nolan"}]
97
-
98
- update = Leftronic.pushList("yourListStream", listArray)
101
+ update = leftronic.push_list "yourListStream", some_array
102
+ ```
103
+ ```ruby
104
+ update = leftronic.push_list "yourListStream", 'Elizabeth', 'Marshall', 'Claire', 'Nolan'
105
+ ```
99
106
  ```
100
107
 
101
108
  Feedback and Issues
data/Rakefile CHANGED
@@ -20,7 +20,8 @@ Jeweler::Tasks.new do |gem|
20
20
  gem.summary = %Q{The official Ruby Gem to interface with the Leftronic API.}
21
21
  gem.description = %Q{Provides a set of functions to update Leftronic dashboard widgets with custom data. Data is submitted by an HTTP POST request with data encoded in the JSON format.}
22
22
  gem.email = "support@leftronic.com"
23
- gem.authors = ["Peter Schaadt"]
23
+ gem.authors = ["Cesar Del Solar"]
24
+ gem.version = '1.2.0'
24
25
  ### dependencies defined in Gemfile
25
26
  end
26
27
  Jeweler::RubygemsDotOrgTasks.new
data/leftronicapi.gemspec CHANGED
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "leftronicapi"
8
- s.version = "1.1.1"
7
+ s.name = %q{leftronicapi}
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Peter Schaadt"]
12
- s.date = "2011-09-28"
13
- s.description = "Provides a set of functions to update Leftronic dashboard widgets with custom data. Data is submitted by an HTTP POST request with data encoded in the JSON format."
14
- s.email = "support@leftronic.com"
11
+ s.authors = ["Cesar Del Solar"]
12
+ s.date = %q{2012-03-22}
13
+ s.description = %q{Provides a set of functions to update Leftronic dashboard widgets with custom data. Data is submitted by an HTTP POST request with data encoded in the JSON format.}
14
+ s.email = %q{support@leftronic.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.md",
@@ -32,16 +32,17 @@ Gem::Specification.new do |s|
32
32
  "test/helper.rb",
33
33
  "test/test_leftronic.rb"
34
34
  ]
35
- s.homepage = "http://github.com/sonofabell/leftronic-ruby"
35
+ s.homepage = %q{http://github.com/sonofabell/leftronic-ruby}
36
36
  s.licenses = ["GNU - LGPL"]
37
37
  s.require_paths = ["lib"]
38
- s.rubygems_version = "1.8.10"
39
- s.summary = "The official Ruby Gem to interface with the Leftronic API."
38
+ s.rubygems_version = %q{1.3.6}
39
+ s.summary = %q{The official Ruby Gem to interface with the Leftronic API.}
40
40
 
41
41
  if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
43
  s.specification_version = 3
43
44
 
44
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
46
  s.add_runtime_dependency(%q<curb>, [">= 0"])
46
47
  s.add_runtime_dependency(%q<json>, [">= 0"])
47
48
  s.add_runtime_dependency(%q<rake>, [">= 0"])
data/lib/leftronic.rb CHANGED
@@ -1,88 +1,84 @@
1
+ require 'net/http'
2
+ require 'net/https'
1
3
  require 'rubygems'
2
- require 'curb'
3
4
  require 'json'
4
5
 
5
6
  class Leftronic
7
+ ALLOWED_COLORS = [:red, :yellow, :green, :blue, :purple]
8
+ attr_accessor :key
9
+ def url=(url)
10
+ @url = URI(url.to_s)
11
+ end
12
+ def url
13
+ @url.to_s
14
+ end
6
15
 
7
- attr_accessor :accessKey
8
-
9
- # Class variable
10
- def initialize(accessKey)
11
- @@accessKey = accessKey
16
+ def initialize(key, url='https://beta.leftronic.com/customSend/')
17
+ @key = key
18
+ self.url = url
12
19
  end
13
20
 
14
- def self.pushNumber(streamName, point)
15
- ### Pushing a number to a Number, Horizontal/Vertical Bar, or Dial widget
16
- parameters = {"accessKey" => @@accessKey, "streamName" => streamName, "point" => point}
17
- # Convert to JSON
18
- jsonData = parameters.to_json()
19
- # Form request
20
- urlRequest = Curl::Easy.http_post("https://beta.leftronic.com/customSend/", jsonData
21
- # Make request
22
- ) do |curl|
23
- curl.headers['Accept'] = 'application/json'
24
- curl.headers['Content-Type'] = 'application/json'
25
- end
21
+ # Push anything to a widget
22
+ def push(stream, object)
23
+ post stream, object
26
24
  end
27
25
 
28
- def self.pushGeo(streamName, lati, longi)
29
- ### Pushing a geographic location (latitude and longitude) to a Map widget
30
- parameters = {"accessKey" => @@accessKey, "streamName" => streamName, "point" => {
31
- "latitude" => lati, "longitude" => longi}}
32
- # Convert to JSON
33
- jsonData = parameters.to_json()
34
- # Form request
35
- urlRequest = Curl::Easy.http_post("https://beta.leftronic.com/customSend/", jsonData
36
- # Make request
37
- ) do |curl|
38
- curl.headers['Accept'] = 'application/json'
39
- curl.headers['Content-Type'] = 'application/json'
40
- end
26
+ # Push a Number to a widget
27
+ def push_number(stream, point)
28
+ post stream, point
41
29
  end
42
-
43
- def self.pushText(streamName, myTitle, myMsg)
44
- ### Pushing a title and message to a Text Feed widget
45
- parameters = {"accessKey" => @@accessKey, "streamName" => streamName, "point" => {
46
- "title" => myTitle, "msg" => myMsg}}
47
- # Convert to JSON
48
- jsonData = parameters.to_json()
49
- # Form request
50
- urlRequest = Curl::Easy.http_post("https://beta.leftronic.com/customSend/", jsonData
51
- # Make request
52
- ) do |curl|
53
- curl.headers['Accept'] = 'application/json'
54
- curl.headers['Content-Type'] = 'application/json'
55
- end
30
+
31
+ # Push a geographic location (latitude and longitude) to a Map widget
32
+ def push_geo(stream, lat, long, color=nil)
33
+ post stream, 'latitude' => lat, 'longitude' => long, 'color' => color
56
34
  end
57
35
 
58
- def self.pushLeaderboard(streamName, leaderArray)
59
- ### Pushing an array to the Leaderboard widget
60
- parameters = {"accessKey" => @@accessKey, "streamName" => streamName, "point" => {
61
- "leaderboard" => leaderArray}}
62
- # Convert to JSON
63
- jsonData = parameters.to_json()
64
- # Form request
65
- urlRequest = Curl::Easy.http_post("https://beta.leftronic.com/customSend/", jsonData
66
- # Make request
67
- ) do |curl|
68
- curl.headers['Accept'] = 'application/json'
69
- curl.headers['Content-Type'] = 'application/json'
70
- end
36
+ # Push a title and message to a Text Feed widget
37
+ def push_text(stream, title, message)
38
+ post stream, 'title' => title, 'msg' => message
71
39
  end
72
-
73
- def self.pushList(streamName, listArray)
74
- ### Pushing an array to the List widget
75
- parameters = {"accessKey" => @@accessKey, "streamName" => streamName, "point" => {
76
- "list" => listArray}}
77
- # Convert to JSON
78
- jsonData = parameters.to_json()
79
- # Form request
80
- urlRequest = Curl::Easy.http_post("https://beta.leftronic.com/customSend/", jsonData
81
- # Make CURL request
82
- ) do |curl|
83
- curl.headers['Accept'] = 'application/json'
84
- curl.headers['Content-Type'] = 'application/json'
85
- end
40
+
41
+ # Push a hash to a Leaderboard widget
42
+ def push_leaderboard(stream, hash)
43
+ leaderboard = hash.inject([]) do |array, (key, value)|
44
+ array << {'name' => key, 'value' => value}
45
+ end
46
+ post stream, 'leaderboard' => leaderboard
86
47
  end
87
48
 
49
+ # Push an array to a List widget
50
+ def push_list(stream, *array)
51
+ post stream, 'list' => array.flatten.map{|item| {'listItem' => item}}
52
+ end
53
+
54
+ protected
55
+
56
+ def post(stream, params)
57
+ request = build_request(stream, params)
58
+ connection = build_connection
59
+ connection.start{|http| http.request request}
60
+ params
61
+ end
62
+
63
+ def build_request(stream, params)
64
+ request = Net::HTTP::Post.new @url.request_uri
65
+ request['Accept'] = 'application/json'
66
+ request['Content-Type'] = 'application/json'
67
+ request.body = {
68
+ 'accessKey' => @key,
69
+ 'streamName' => stream,
70
+ 'point' => params
71
+ }.to_json
72
+ request
73
+ end
74
+
75
+ def build_connection # NOTE: Does not open the connection
76
+ connection = Net::HTTP.new @url.host, @url.port
77
+ if @url.scheme == 'https'
78
+ connection.use_ssl = true
79
+ connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
80
+ end
81
+ connection
82
+ end
88
83
  end
84
+
metadata CHANGED
@@ -1,124 +1,110 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leftronicapi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 1
8
- - 1
9
- - 1
10
- version: 1.1.1
7
+ - 2
8
+ - 0
9
+ version: 1.2.0
11
10
  platform: ruby
12
11
  authors:
13
- - Peter Schaadt
12
+ - Cesar Del Solar
14
13
  autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-09-28 00:00:00 Z
17
+ date: 2012-03-22 00:00:00 -07:00
18
+ default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- requirement: &id001 !ruby/object:Gem::Requirement
22
- none: false
21
+ prerelease: false
22
+ type: :runtime
23
+ name: curb
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
25
  requirements:
24
26
  - - ">="
25
27
  - !ruby/object:Gem::Version
26
- hash: 3
27
28
  segments:
28
29
  - 0
29
30
  version: "0"
30
- version_requirements: *id001
31
- name: curb
31
+ requirement: *id001
32
+ - !ruby/object:Gem::Dependency
32
33
  prerelease: false
33
34
  type: :runtime
34
- - !ruby/object:Gem::Dependency
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- none: false
35
+ name: json
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- hash: 3
41
40
  segments:
42
41
  - 0
43
42
  version: "0"
44
- version_requirements: *id002
45
- name: json
43
+ requirement: *id002
44
+ - !ruby/object:Gem::Dependency
46
45
  prerelease: false
47
46
  type: :runtime
48
- - !ruby/object:Gem::Dependency
49
- requirement: &id003 !ruby/object:Gem::Requirement
50
- none: false
47
+ name: rake
48
+ version_requirements: &id003 !ruby/object:Gem::Requirement
51
49
  requirements:
52
50
  - - ">="
53
51
  - !ruby/object:Gem::Version
54
- hash: 3
55
52
  segments:
56
53
  - 0
57
54
  version: "0"
58
- version_requirements: *id003
59
- name: rake
60
- prerelease: false
61
- type: :runtime
55
+ requirement: *id003
62
56
  - !ruby/object:Gem::Dependency
63
- requirement: &id004 !ruby/object:Gem::Requirement
64
- none: false
57
+ prerelease: false
58
+ type: :development
59
+ name: shoulda
60
+ version_requirements: &id004 !ruby/object:Gem::Requirement
65
61
  requirements:
66
62
  - - ">="
67
63
  - !ruby/object:Gem::Version
68
- hash: 3
69
64
  segments:
70
65
  - 0
71
66
  version: "0"
72
- version_requirements: *id004
73
- name: shoulda
67
+ requirement: *id004
68
+ - !ruby/object:Gem::Dependency
74
69
  prerelease: false
75
70
  type: :development
76
- - !ruby/object:Gem::Dependency
77
- requirement: &id005 !ruby/object:Gem::Requirement
78
- none: false
71
+ name: bundler
72
+ version_requirements: &id005 !ruby/object:Gem::Requirement
79
73
  requirements:
80
74
  - - ~>
81
75
  - !ruby/object:Gem::Version
82
- hash: 23
83
76
  segments:
84
77
  - 1
85
78
  - 0
86
79
  - 0
87
80
  version: 1.0.0
88
- version_requirements: *id005
89
- name: bundler
81
+ requirement: *id005
82
+ - !ruby/object:Gem::Dependency
90
83
  prerelease: false
91
84
  type: :development
92
- - !ruby/object:Gem::Dependency
93
- requirement: &id006 !ruby/object:Gem::Requirement
94
- none: false
85
+ name: jeweler
86
+ version_requirements: &id006 !ruby/object:Gem::Requirement
95
87
  requirements:
96
88
  - - ~>
97
89
  - !ruby/object:Gem::Version
98
- hash: 7
99
90
  segments:
100
91
  - 1
101
92
  - 6
102
93
  - 4
103
94
  version: 1.6.4
104
- version_requirements: *id006
105
- name: jeweler
95
+ requirement: *id006
96
+ - !ruby/object:Gem::Dependency
106
97
  prerelease: false
107
98
  type: :development
108
- - !ruby/object:Gem::Dependency
109
- requirement: &id007 !ruby/object:Gem::Requirement
110
- none: false
99
+ name: rcov
100
+ version_requirements: &id007 !ruby/object:Gem::Requirement
111
101
  requirements:
112
102
  - - ">="
113
103
  - !ruby/object:Gem::Version
114
- hash: 3
115
104
  segments:
116
105
  - 0
117
106
  version: "0"
118
- version_requirements: *id007
119
- name: rcov
120
- prerelease: false
121
- type: :development
107
+ requirement: *id007
122
108
  description: Provides a set of functions to update Leftronic dashboard widgets with custom data. Data is submitted by an HTTP POST request with data encoded in the JSON format.
123
109
  email: support@leftronic.com
124
110
  executables: []
@@ -143,6 +129,7 @@ files:
143
129
  - lib/leftronic.rb
144
130
  - test/helper.rb
145
131
  - test/test_leftronic.rb
132
+ has_rdoc: true
146
133
  homepage: http://github.com/sonofabell/leftronic-ruby
147
134
  licenses:
148
135
  - GNU - LGPL
@@ -152,27 +139,23 @@ rdoc_options: []
152
139
  require_paths:
153
140
  - lib
154
141
  required_ruby_version: !ruby/object:Gem::Requirement
155
- none: false
156
142
  requirements:
157
143
  - - ">="
158
144
  - !ruby/object:Gem::Version
159
- hash: 3
160
145
  segments:
161
146
  - 0
162
147
  version: "0"
163
148
  required_rubygems_version: !ruby/object:Gem::Requirement
164
- none: false
165
149
  requirements:
166
150
  - - ">="
167
151
  - !ruby/object:Gem::Version
168
- hash: 3
169
152
  segments:
170
153
  - 0
171
154
  version: "0"
172
155
  requirements: []
173
156
 
174
157
  rubyforge_project:
175
- rubygems_version: 1.8.10
158
+ rubygems_version: 1.3.6
176
159
  signing_key:
177
160
  specification_version: 3
178
161
  summary: The official Ruby Gem to interface with the Leftronic API.