thingspeak-api 0.1.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ ThingSpeak API
2
+ ==============
3
+
4
+ This is a Ruby wrapper for interacting with the ThingSpeak (http://www.thingspeak.com) REST API from Ruby programs.
5
+ API docs for ThingSpeak can be found at http://community.thingspeak.com/documentation/api/
6
+
7
+ **NOTE: This gem is still prerelease and under development.**
8
+
9
+ To use, simply include it in your Gemfile:
10
+
11
+ gem 'thingspeak-api'
12
+
13
+ or install from the command line:
14
+
15
+ gem install 'thingspeak-api'
16
+
17
+ Create a client with your read key and write key and send a message to your channel:
18
+
19
+ ```ruby
20
+ require 'thingspeak'
21
+
22
+ client = ThingSpeak::Client.new("YOUR_WRITE_KEY", "YOUR_READ_KEY")
23
+
24
+ # post an update to your channel, returns the identifier of the new post if successful
25
+ client.update_channel({field1: "foo", field2: "bar"}) # => 3
26
+
27
+ ```
28
+
29
+
30
+ License
31
+ -------
32
+
33
+ MIT License
34
+
35
+ Copyright (c) 2012 Daniel Treacy
36
+
37
+ Permission is hereby granted, free of charge, to any person obtaining
38
+ a copy of this software and associated documentation files (the
39
+ 'Software'), to deal in the Software without restriction, including
40
+ without limitation the rights to use, copy, modify, merge, publish,
41
+ distribute, sublicense, and/or sell copies of the Software, and to
42
+ permit persons to whom the Software is furnished to do so, subject to
43
+ the following conditions:
44
+
45
+ The above copyright notice and this permission notice shall be
46
+ included in all copies or substantial portions of the Software.
47
+
48
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
49
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
50
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
51
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
52
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
53
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
54
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/thingspeak.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'thingspeak/version'
2
+ require 'thingspeak/paths'
3
+ require 'thingspeak/exceptions'
4
+ require 'thingspeak/request'
5
+ require 'thingspeak/update'
6
+ require 'thingspeak/client'
@@ -0,0 +1,22 @@
1
+ require 'rest_client'
2
+
3
+ module ThingSpeak
4
+ class Client
5
+ def initialize(write_key, read_key)
6
+ @write_key = write_key
7
+ @read_key = read_key
8
+
9
+ self
10
+ end
11
+
12
+ def update_channel(hash)
13
+ update = ThingSpeak::Update.new(hash)
14
+
15
+ begin
16
+ RestClient.post ThingSpeak::THINGSPEAK_UPDATE_URL, update.build_params.with_key(@write_key)
17
+ rescue
18
+ puts "RestClient error"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ module ThingSpeak
2
+ module Exceptions
3
+
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module ThingSpeak
2
+
3
+ THINGSPEAK_BASE_URL = "http://api.thingspeak.com"
4
+ THINGSPEAK_UPDATE_URL = "#{THINGSPEAK_BASE_URL}/update"
5
+
6
+ end
@@ -0,0 +1,25 @@
1
+ module ThingSpeak
2
+ class Request
3
+ def build_params
4
+ params = {}
5
+
6
+ self.params.each do |k, v|
7
+ params[k] = v
8
+ end
9
+
10
+ params[:lat] = self.lat if self.lat
11
+ params[:long] = self.long if self.long
12
+ params[:elevation] = self.elevation if self.elevation
13
+ params[:status] = self.status if self.status
14
+ params[:twitter] = self.twitter if self.twitter
15
+ params[:tweet] = self.tweet if self.tweet
16
+
17
+ params.class.send(:define_method, :with_key) do |key|
18
+ self[:key] = key
19
+ self
20
+ end
21
+
22
+ params
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ module ThingSpeak
2
+
3
+ class Update < Request
4
+ attr_accessor :params, :lat, :long, :elevation, :status, :twitter, :tweet
5
+
6
+ def initialize(params, location = {}, status = nil, twitter = nil, tweet = nil)
7
+ raise ArgumentError.new("First argument to Update#new should be a Hash.") unless params.instance_of?(Hash)
8
+
9
+ self.params = params
10
+ self.lat = location[:lat]
11
+ self.long = location[:long]
12
+ self.elevation = location[:elevation]
13
+ self.status = status
14
+ self.twitter = twitter
15
+ self.tweet = tweet
16
+
17
+ self
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,5 @@
1
+ module ThingSpeak
2
+
3
+ VERSION = "0.1.pre" unless defined?(::ThingSpeak::VERSION)
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thingspeak-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.pre
5
+ prerelease: 4
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Treacy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70199655853840 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70199655853840
25
+ - !ruby/object:Gem::Dependency
26
+ name: rest-client
27
+ requirement: &70199655853400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70199655853400
36
+ description: A wrapper for the ThingSpeak API to make interacting with your ThingSpeak
37
+ channels easy from Ruby-based applications
38
+ email: daniel.t.treacy@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - lib/thingspeak/client.rb
44
+ - lib/thingspeak/exceptions.rb
45
+ - lib/thingspeak/paths.rb
46
+ - lib/thingspeak/request.rb
47
+ - lib/thingspeak/update.rb
48
+ - lib/thingspeak/version.rb
49
+ - lib/thingspeak.rb
50
+ - README.md
51
+ homepage: http://github.com/danieltreacy/thingspeak-api
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>'
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.1
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.17
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Ruby DSL for interacting with ThingSpeak API
75
+ test_files: []