thingdeck 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a799712397f7188680e156e4779f4d71e3fa5af4
4
- data.tar.gz: c3681d4536225db0567cb9a07ca78b10ad446f7b
3
+ metadata.gz: 426781396808726b8c3188c715e655f50c7216f7
4
+ data.tar.gz: 1ce14d23697149d47c8b1c94452efd5aec87f125
5
5
  SHA512:
6
- metadata.gz: c6c16a0db94ba94e08e2c47fbe383a6741a7388ee9e39c539ff91aa3a348345c0ab7ab4cbbdc0723b72c2a5a5e434f3b935c30bd56114e212b12c03ae095a92d
7
- data.tar.gz: 560890491e95c8166cd67695b2b4d7983f7aaa854417ec354be7d7e499c2e8b0122d1c54df194b7d215d683bdd665093472afef033b814a8a4ba6441c55e13cf
6
+ metadata.gz: 38d2f7a6df601f20cb8c7640802d4ea676eb68875c497eef2219c3d1c547aa5da02cfdde3f31a1d196f83e9ed075e943709ba2ea3eb65504e82b722b07241067
7
+ data.tar.gz: 71248933cb5d773ad09b03e8b71151f32e6517f369d6be268b63dd2ba24b6395edb2c1e1c006bfb9387cbb8c099b972537506061c16c4a7e3e97a55db4d4b5f8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- thingdeck (0.0.2)
4
+ thingdeck (0.0.3)
5
5
  faraday
6
6
  json
7
7
 
data/lib/thingdeck.rb CHANGED
@@ -1,10 +1,16 @@
1
1
  require 'faraday'
2
2
  require 'json'
3
3
 
4
- require "thingdeck/version"
5
- require "thingdeck/wrapper"
6
- require "thingdeck/item"
7
- require "thingdeck/property"
4
+ require 'thingdeck/version'
5
+ require 'thingdeck/wrapper'
6
+
7
+ require 'thingdeck/item'
8
+ require 'thingdeck/nested_item'
9
+ require 'thingdeck/collections/thing'
10
+
11
+ require 'thingdeck/collection'
12
+ require 'thingdeck/property'
13
+ require 'thingdeck/thing'
8
14
 
9
15
  module Thingdeck
10
16
  OAUTH_URL = 'http://staging.thingdeck.com'
@@ -0,0 +1,15 @@
1
+ module Thingdeck
2
+ class Collection < Item
3
+ def initialize(wrapper)
4
+ super(wrapper, 'collections')
5
+ end
6
+
7
+ def things
8
+ @things ||= Collections::Thing.new(@wrapper)
9
+ end
10
+
11
+ def update
12
+ raise NotImplementedError
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module Thingdeck
2
+ module Collections
3
+ class Thing < NestedItem
4
+ def initialize(wrapper)
5
+ super(wrapper, 'collections', 'things')
6
+ end
7
+ end
8
+ end
9
+ end
@@ -14,7 +14,7 @@ module Thingdeck
14
14
  end
15
15
 
16
16
  def update(id, params)
17
- @wrapper.perform_request { |c| c.put(url(id), params) }
17
+ @wrapper.perform_request { |c| c.put(url(id), params) }
18
18
  end
19
19
 
20
20
  def create(params)
@@ -27,7 +27,7 @@ module Thingdeck
27
27
 
28
28
  private
29
29
  def url(id)
30
- [ @uri, id ].join('/')
30
+ '/' + [ @uri, id ].join('/')
31
31
  end
32
32
  end
33
33
  end
@@ -0,0 +1,34 @@
1
+ module Thingdeck
2
+ class NestedItem
3
+ def initialize(wrapper, parent, uri)
4
+ @wrapper = wrapper
5
+ @parent = parent
6
+ @uri = uri
7
+ end
8
+
9
+ def all(pid, params = {})
10
+ @wrapper.perform_request { |c| c.get(url(pid), params) }
11
+ end
12
+
13
+ def find(pid, id, params = {})
14
+ @wrapper.perform_request { |c| c.get(url(pid, id), params) }
15
+ end
16
+
17
+ def update(pid, id, params)
18
+ @wrapper.perform_request { |c| c.put(url(pid, id), params) }
19
+ end
20
+
21
+ def create(pid, params)
22
+ @wrapper.perform_request { |c| c.post(url(pid), params) }
23
+ end
24
+
25
+ def destroy(pid, id)
26
+ @wrapper.perform_request { |c| c.delete(url(pid, id)) }
27
+ end
28
+
29
+ private
30
+ def url(pid, id = '')
31
+ '/' + [ @parent, pid, @uri, id ].join('/')
32
+ end
33
+ end
34
+ end
@@ -1,37 +1,11 @@
1
1
  module Thingdeck
2
- class Property
3
- def initialize(wrapper)
4
- @wrapper = wrapper
2
+ class Property < NestedItem
3
+ def initialize(wrapper, parent)
4
+ super(wrapper, parent, 'properties')
5
5
  end
6
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, params = {})
13
- url = single_url(id, type, pid)
14
- @wrapper.perform_request { |c| c.get(url, params) }
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}"
7
+ def update
8
+ raise NotImplementedError
35
9
  end
36
10
  end
37
11
  end
@@ -0,0 +1,11 @@
1
+ module Thingdeck
2
+ class Thing < Item
3
+ def initialize(wrapper)
4
+ super(wrapper, 'things')
5
+ end
6
+
7
+ def properties
8
+ @properties ||= Property.new(@wrapper, 'things')
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Thingdeck
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -8,12 +8,12 @@ module Thingdeck
8
8
  !!@token
9
9
  end
10
10
 
11
- def thing
12
- @things ||= Item.new(self, '/things')
11
+ def collections
12
+ @collections ||= Collection.new(self)
13
13
  end
14
14
 
15
- def property
16
- @properties ||= Property.new(self)
15
+ def things
16
+ @things ||= Thing.new(self)
17
17
  end
18
18
 
19
19
  def perform_request(need_auth = true)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thingdeck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - thingdeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-18 00:00:00.000000000 Z
11
+ date: 2013-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,8 +108,12 @@ files:
108
108
  - README.md
109
109
  - Rakefile
110
110
  - lib/thingdeck.rb
111
+ - lib/thingdeck/collection.rb
112
+ - lib/thingdeck/collections/thing.rb
111
113
  - lib/thingdeck/item.rb
114
+ - lib/thingdeck/nested_item.rb
112
115
  - lib/thingdeck/property.rb
116
+ - lib/thingdeck/thing.rb
113
117
  - lib/thingdeck/version.rb
114
118
  - lib/thingdeck/wrapper.rb
115
119
  - spec/item_spec.rb