thingdeck 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2198a8891307a75c9f803a3815f6c88f3f51fb5b
4
+ data.tar.gz: 84adee59475d45d89a9aee2241ef1ae5e98302c3
5
+ SHA512:
6
+ metadata.gz: e33eee3fda283fb3fe70799b0f77d5330cd9c63c646cc5f1e92e5456e94ebaa7becd2f9348154fb3a37c7981c7e0e08ded5306189eb26d55767311f6780acf43
7
+ data.tar.gz: 621b600934759ae09b72e6e7fecfdfb03e0808e0701a433680d3e0f12eeea425b092cddb679d4644f32873ce2491878ac497a04a6cabd0befccbf1da6a828b0f
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in thingdeck.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ thingdeck (0.0.1)
5
+ faraday
6
+ json
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.3.5)
12
+ crack (0.4.1)
13
+ safe_yaml (~> 0.9.0)
14
+ diff-lcs (1.2.5)
15
+ faraday (0.8.8)
16
+ multipart-post (~> 1.2.0)
17
+ json (1.8.1)
18
+ multipart-post (1.2.0)
19
+ rake (10.1.0)
20
+ rspec (2.14.1)
21
+ rspec-core (~> 2.14.0)
22
+ rspec-expectations (~> 2.14.0)
23
+ rspec-mocks (~> 2.14.0)
24
+ rspec-core (2.14.7)
25
+ rspec-expectations (2.14.4)
26
+ diff-lcs (>= 1.1.3, < 2.0)
27
+ rspec-mocks (2.14.4)
28
+ safe_yaml (0.9.7)
29
+ webmock (1.15.2)
30
+ addressable (>= 2.2.7)
31
+ crack (>= 0.3.2)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.3)
38
+ rake
39
+ rspec
40
+ thingdeck!
41
+ webmock
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 ThingDeck
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ thingdeck-ruby
2
+ ==============
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,33 @@
1
+ module Thingdeck
2
+ class Item
3
+ def initialize(wrapper, uri = '')
4
+ @wrapper = wrapper
5
+ @uri = uri
6
+ end
7
+
8
+ def all(params = nil)
9
+ @wrapper.perform_request { |c| c.get(@uri, params) }
10
+ end
11
+
12
+ def find(id)
13
+ @wrapper.perform_request { |c| c.get(url(id)) }
14
+ end
15
+
16
+ def update(id, params)
17
+ @wrapper.perform_request { |c| c.put(url(id), params) }
18
+ end
19
+
20
+ def create(params)
21
+ @wrapper.perform_request { |c| c.post(@uri, params) }
22
+ end
23
+
24
+ def destroy(id)
25
+ @wrapper.perform_request { |c| c.delete(url(id)) }
26
+ end
27
+
28
+ private
29
+ def url(id)
30
+ [ @uri, id ].join('/')
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ module Thingdeck
2
+ class Property
3
+ def initialize(wrapper)
4
+ @wrapper = wrapper
5
+ end
6
+
7
+ def all(id, type, params = {})
8
+ url = collection_url(id, type)
9
+ @wrapper.perform_request { |c| c.get(url, params) }
10
+ end
11
+
12
+ def find(id, type, pid)
13
+ url = single_url(id, type, pid)
14
+ @wrapper.perform_request { |c| c.get(url) }
15
+ end
16
+
17
+ def create(id, type, params)
18
+ url = collection_url(id, type)
19
+ @wrapper.perform_request { |c| c.post(url, params) }
20
+ end
21
+
22
+ def destroy(id, type, pid)
23
+ url = single_url(id, type, pid)
24
+ @wrapper.perform_request { |c| c.delete(url) }
25
+ end
26
+
27
+ private
28
+ def collection_url(id, type)
29
+ raise 'Invalid item type' unless [ :products, :things ].include?(type)
30
+ "/#{type}/#{id}/properties"
31
+ end
32
+
33
+ def single_url(id, type, pid)
34
+ "#{collection_url(id, type)}/#{pid}"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Thingdeck
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,43 @@
1
+ module Thingdeck
2
+ class Wrapper
3
+ def initialize(app_id, secret)
4
+ @token = authenticate(app_id, secret)
5
+ end
6
+
7
+ def authorized?
8
+ !!@token
9
+ end
10
+
11
+ def thing
12
+ @things ||= Item.new(self, '/things')
13
+ end
14
+
15
+ def property
16
+ @properties ||= Property.new(self)
17
+ end
18
+
19
+ def perform_request(need_auth = true)
20
+ raise 'Not Authorized' if need_auth and not authorized?
21
+ response = yield(connection)
22
+ parse_body(response)
23
+ end
24
+
25
+ private
26
+ def parse_body(response)
27
+ body = response.env[:body].strip
28
+ JSON[body]
29
+ rescue
30
+ nil
31
+ end
32
+
33
+ def connection
34
+ @connection ||= Faraday.new(url: API_URL, headers: { 'Accept' => 'application/json; version=1', 'Authorization' => "Token #{@token}" })
35
+ end
36
+
37
+ def authenticate(app_id, secret)
38
+ response = Faraday.new(url: OAUTH_URL).post('/oauth/token', application_id: app_id, secret: secret)
39
+ auth = parse_body(response)
40
+ token = auth['token'] unless auth.nil?
41
+ end
42
+ end
43
+ end
data/lib/thingdeck.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ require "thingdeck/version"
5
+ require "thingdeck/wrapper"
6
+ require "thingdeck/item"
7
+ require "thingdeck/property"
8
+
9
+ module Thingdeck
10
+ OAUTH_URL = 'http://staging.thingdeck.com'
11
+ API_URL = 'http://staging.api.thingdeck.com/'
12
+ end
data/spec/item_spec.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Thingdeck::Item do
4
+ let(:wrapper) { double('wrapper') }
5
+ let(:uri) { double('uri') }
6
+
7
+ subject { Thingdeck::Item.new(wrapper, uri) }
8
+
9
+ [ :all, :find, :update, :create, :destroy ].each do |action|
10
+ it { should respond_to(action) }
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Thingdeck::Property do
4
+ let(:wrapper) { double('wrapper') }
5
+
6
+ subject { Thingdeck::Property.new(wrapper) }
7
+
8
+ [ :all, :find, :create, :destroy ].each do |action|
9
+ it { should respond_to(action) }
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ require 'bundler/setup'
2
+ require 'webmock/rspec'
3
+ require 'thingdeck'
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Thingdeck::Wrapper do
4
+ let(:app_id) { 'app_id' }
5
+ let(:secret) { 'secret' }
6
+ let(:token) { 'w32vd234231rr' }
7
+ let(:response) { "{\"token\": \"#{token}\"}" }
8
+
9
+ let(:wrapper) { wrapper = Thingdeck::Wrapper.new(app_id, secret) }
10
+ let(:tid) { 'AABAJ' }
11
+
12
+ before do
13
+ stub_request(:post, "#{Thingdeck::OAUTH_URL}/oauth/token").
14
+ to_return(:status => 200, :body => response, :headers => {})
15
+ stub_request(:post, "#{Thingdeck::API_URL}/things/")
16
+ stub_request(:post, "#{Thingdeck::API_URL}/things/#{tid}")
17
+ end
18
+
19
+ it 'authenticates user after initializing' do
20
+ wrapper.should be_authorized
21
+ end
22
+
23
+ it 'initializes thing' do
24
+ wrapper.thing.should_not be_nil
25
+ end
26
+
27
+ it 'initializes property' do
28
+ wrapper.property.should_not be_nil
29
+ end
30
+ end
data/thingdeck.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'thingdeck/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'thingdeck'
8
+ spec.version = Thingdeck::VERSION
9
+ spec.authors = ['thingdeck']
10
+ spec.email = ['v@gor.io']
11
+ spec.description = %q{Thingdeck gem}
12
+ spec.summary = %q{Summary}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'webmock'
25
+
26
+ spec.add_dependency 'faraday'
27
+ spec.add_dependency 'json'
28
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thingdeck
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - thingdeck
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Thingdeck gem
98
+ email:
99
+ - v@gor.io
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - LICENSE
108
+ - README.md
109
+ - Rakefile
110
+ - lib/thingdeck.rb
111
+ - lib/thingdeck/item.rb
112
+ - lib/thingdeck/property.rb
113
+ - lib/thingdeck/version.rb
114
+ - lib/thingdeck/wrapper.rb
115
+ - spec/item_spec.rb
116
+ - spec/property_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/wrapper_spec.rb
119
+ - thingdeck.gemspec
120
+ homepage: ''
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.0.7
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Summary
144
+ test_files:
145
+ - spec/item_spec.rb
146
+ - spec/property_spec.rb
147
+ - spec/spec_helper.rb
148
+ - spec/wrapper_spec.rb