phant_rb 0.1.0 → 0.2.0

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: 17838ed9df5576d26e9c8ce00811e647f5edc3d5
4
- data.tar.gz: 2f61e56fb9dc21398b4d98cacaca28a31a249c47
3
+ metadata.gz: ab778e359b2ffcd7606fd5e74adf112b0ee4a2dd
4
+ data.tar.gz: 5144a0ff72ce5193d4de5b0b0317d401994421ab
5
5
  SHA512:
6
- metadata.gz: 351f3e77f750359d37bab877344284ddb828c9070422f79d18e7353b50b330262387b22b27118aa52633e80cce195e345f9f33ed8d7aebe38aaeaae23a39a3a5
7
- data.tar.gz: dde8cd909d22e1da291b7edace160fdb2f2621d2dd69c19aad4a16d213e66b5f635a3f0292f5987f9c7a0cccbfa103e9b6b738a03d221362a7c272e2eeed543f
6
+ metadata.gz: bdaa25bfecd3d2f816b9b6ec52254b49acd1e5f100f58bbd81034e417dc318d9e829a9b93ac6cbedc7c9a7f99d2ae301625ab2d92737ebcc6d03f0d97ef9a4c9
7
+ data.tar.gz: 1e0359860df56f08459f1de014e5298c09f77786da895da1e26b00ff0baaaee716a80a9e661824992cdd7bfc86e82880fddffcdf56bd294cf0fc4ac639d76f13
data/README.md CHANGED
@@ -30,6 +30,9 @@ client.log(22.7, 17.8)
30
30
  data = client.get()
31
31
  puts data
32
32
 
33
+ # paginate data
34
+ data = client.get(page: 1)
35
+
33
36
  # retrieve info about the current state of your stream, http://phant.io/docs/output/stats/
34
37
  stats = client.stats()
35
38
  puts stats.pageCount
@@ -53,7 +56,6 @@ client = PhantRb::Client.new "PUBLIC_KEY", %w(humidity temp), {private_key: 'PRI
53
56
 
54
57
  ## TODO
55
58
  * delete a stream
56
- * paginate data
57
59
  * use local server in specs
58
60
 
59
61
  ## Contributing
@@ -1,3 +1,3 @@
1
1
  module PhantRb
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/phant_rb.rb CHANGED
@@ -19,8 +19,8 @@ module PhantRb
19
19
  Hashie::Mash.new(JSON.parse(@last_response.body))
20
20
  end
21
21
 
22
- def get
23
- conn = rest_conn 'output'
22
+ def get(params = {})
23
+ conn = rest_conn 'output', params
24
24
  response = conn.get
25
25
  JSON.parse response.body
26
26
  end
@@ -45,11 +45,17 @@ module PhantRb
45
45
  end
46
46
 
47
47
  private
48
- def rest_conn(type)
48
+ def rest_conn(type, params = nil)
49
49
  url = case type
50
50
  when 'stats' then URI.join @opts[:base_url], "/output/", "#{@public_key}/stats.json"
51
- else URI.join @opts[:base_url], "/#{type}/", "#{@public_key}.json"
51
+ else
52
+ if params.nil?
53
+ URI.join @opts[:base_url], "/#{type}/", "#{@public_key}.json"
54
+ else
55
+ URI.join @opts[:base_url], "/#{type}/", "#{@public_key}.json?" + URI.encode_www_form(params)
56
+ end
52
57
  end
58
+
53
59
  RestClient::Resource.new url.to_s,
54
60
  {:headers => {'Phant-Private-Key' => @opts[:private_key]}}
55
61
  end
@@ -22,6 +22,11 @@ describe PhantRb do
22
22
  expect(resp).to be_an(Array)
23
23
  end
24
24
 
25
+ it 'reads paginated data' do
26
+ resp = @client.get(page: 1)
27
+ expect(resp).to be_an(Array)
28
+ end
29
+
25
30
  it 'returns stats for a stream' do
26
31
  resp = @client.stats
27
32
  expect(resp.has_key?(:remaining)).to be true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phant_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Girish S
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-14 00:00:00.000000000 Z
11
+ date: 2014-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client