jawbone_up-client 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +5 -0
- data/jawbone_up-client.gemspec +6 -0
- data/lib/jawbone_up/client.rb +54 -2
- data/lib/jawbone_up/client/configuration.rb +10 -0
- data/lib/jawbone_up/client/response.rb +46 -0
- data/lib/jawbone_up/client/response/item.rb +45 -0
- data/lib/jawbone_up/client/response/meta.rb +13 -0
- data/lib/jawbone_up/client/version.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- metadata +94 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad56b18d2326d0372e806c072cf427617e7a77cd
|
4
|
+
data.tar.gz: b08a03923dd2a9dbb823beaed3ea4cd07fbdee44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a505445f535b3f0a25e3d5a4095c6cd349d0cbac8e2ce030a7a886a38f01fabc034203bbfb805abe9755e57b0deb80aa7f0fa6e19582e57ab2bbdc19279fa6f
|
7
|
+
data.tar.gz: 617eec1186140f61c28217cf8dea821edf1581158d934495663e4042357bba81db2b019d3e751c0bc2bc59f45a993b1f56db8df9af6d5b48d874dbaeabc2bf61
|
data/Guardfile
ADDED
data/jawbone_up-client.gemspec
CHANGED
@@ -18,6 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "rest-client"
|
22
|
+
spec.add_dependency "activesupport"
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
24
|
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "guard-rspec"
|
27
|
+
spec.add_development_dependency "terminal-notifier-guard"
|
28
|
+
spec.add_development_dependency "webmock"
|
23
29
|
end
|
data/lib/jawbone_up/client.rb
CHANGED
@@ -1,7 +1,59 @@
|
|
1
|
+
require 'restclient'
|
2
|
+
require 'active_support/all'
|
1
3
|
require "jawbone_up/client/version"
|
4
|
+
require 'jawbone_up/client/configuration'
|
5
|
+
require 'jawbone_up/client/response'
|
2
6
|
|
3
7
|
module JawboneUp
|
4
|
-
|
5
|
-
|
8
|
+
class Client
|
9
|
+
BASE_URL = "https://jawbone.com"
|
10
|
+
|
11
|
+
API_VERSION = "v.1.1"
|
12
|
+
|
13
|
+
API_URL = "#{BASE_URL}/nudge/api/#{API_VERSION}"
|
14
|
+
|
15
|
+
def self.configure(&block)
|
16
|
+
yield config
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.config
|
20
|
+
@config ||= Configuration.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(token)
|
24
|
+
@token = token
|
25
|
+
end
|
26
|
+
|
27
|
+
def get(path, params: {}, headers: {})
|
28
|
+
request(:get, path, params: params, headers: headers)
|
29
|
+
end
|
30
|
+
|
31
|
+
def post(path, payload: nil, params: {}, headers: {})
|
32
|
+
request(:post, path, payload: payload, params: params, headers: headers)
|
33
|
+
end
|
34
|
+
|
35
|
+
def put(path, payload: nil, params: {}, headers: {})
|
36
|
+
request(:put, path, payload: payload, params: params, headers: headers)
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete(path, params: {}, headers: {})
|
40
|
+
request(:delete, path, params: params, headers: headers)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def request(method, path, payload: nil, params: {}, headers: {})
|
46
|
+
Response.new(
|
47
|
+
RestClient::Request.execute(
|
48
|
+
method: method,
|
49
|
+
url: "#{API_URL}#{path}",
|
50
|
+
payload: payload,
|
51
|
+
headers: {
|
52
|
+
params: params,
|
53
|
+
authorization: "Bearer #{@token}"
|
54
|
+
}.merge(headers)
|
55
|
+
)
|
56
|
+
)
|
57
|
+
end
|
6
58
|
end
|
7
59
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'jawbone_up/client/response/meta'
|
2
|
+
require 'jawbone_up/client/response/item'
|
3
|
+
|
4
|
+
module JawboneUp
|
5
|
+
class Client
|
6
|
+
class Response
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
def initialize(response)
|
10
|
+
@response = response
|
11
|
+
end
|
12
|
+
|
13
|
+
def code
|
14
|
+
@response.code
|
15
|
+
end
|
16
|
+
|
17
|
+
def headers
|
18
|
+
@response.headers
|
19
|
+
end
|
20
|
+
|
21
|
+
def meta
|
22
|
+
@meta ||= Meta.new(@response)
|
23
|
+
end
|
24
|
+
|
25
|
+
def each
|
26
|
+
if data.has_key?('items')
|
27
|
+
data['items'].each do |item|
|
28
|
+
yield Item.new(item)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
yield Item.new(data)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def [](key)
|
36
|
+
data[key]
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def data
|
42
|
+
@data ||= JSON.parse(@response)['data']
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module JawboneUp
|
2
|
+
class Client
|
3
|
+
class Response
|
4
|
+
class Item < OpenStruct
|
5
|
+
TYPES = {
|
6
|
+
'time_created' => DateTime,
|
7
|
+
'time_completed' => DateTime,
|
8
|
+
'date' => Date,
|
9
|
+
'place_lat' => Float,
|
10
|
+
'place_lon' => Float,
|
11
|
+
'snapshot_image' => URI
|
12
|
+
}
|
13
|
+
|
14
|
+
def initialize(hash)
|
15
|
+
super(normarize(hash))
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def normarize(hash)
|
21
|
+
TYPES.each do |key, type|
|
22
|
+
if hash.has_key?(key)
|
23
|
+
hash[key] = cast(hash[key], type)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
hash
|
27
|
+
end
|
28
|
+
|
29
|
+
def cast(value, type)
|
30
|
+
if type == DateTime
|
31
|
+
DateTime.strptime(value.to_s, '%s')
|
32
|
+
elsif type == Date
|
33
|
+
Date.parse(value.to_s)
|
34
|
+
elsif type == Float
|
35
|
+
value.to_f
|
36
|
+
elsif type == URI
|
37
|
+
"#{JawboneUp::Client::BASE_URL}#{value}"
|
38
|
+
else
|
39
|
+
value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'jawbone_up-client'
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jawbone_up-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takatoshi Maeda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +66,62 @@ dependencies:
|
|
38
66
|
- - ">="
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
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: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: terminal-notifier-guard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
41
125
|
description: Support JawboneUp authentication and api tool.
|
42
126
|
email:
|
43
127
|
- me@tmd.tw
|
@@ -47,12 +131,18 @@ extra_rdoc_files: []
|
|
47
131
|
files:
|
48
132
|
- ".gitignore"
|
49
133
|
- Gemfile
|
134
|
+
- Guardfile
|
50
135
|
- LICENSE.txt
|
51
136
|
- README.md
|
52
137
|
- Rakefile
|
53
138
|
- jawbone_up-client.gemspec
|
54
139
|
- lib/jawbone_up/client.rb
|
140
|
+
- lib/jawbone_up/client/configuration.rb
|
141
|
+
- lib/jawbone_up/client/response.rb
|
142
|
+
- lib/jawbone_up/client/response/item.rb
|
143
|
+
- lib/jawbone_up/client/response/meta.rb
|
55
144
|
- lib/jawbone_up/client/version.rb
|
145
|
+
- spec/spec_helper.rb
|
56
146
|
homepage: https://github.com/TakatoshiMaeda/jawbone_up-client
|
57
147
|
licenses:
|
58
148
|
- MIT
|
@@ -77,4 +167,5 @@ rubygems_version: 2.2.2
|
|
77
167
|
signing_key:
|
78
168
|
specification_version: 4
|
79
169
|
summary: JawboneUp api client
|
80
|
-
test_files:
|
170
|
+
test_files:
|
171
|
+
- spec/spec_helper.rb
|