passtools 0.3.0 → 0.4.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.
- data/README.md +15 -0
- data/lib/passtools/pass.rb +30 -5
- data/lib/passtools/request.rb +16 -4
- data/lib/passtools/template.rb +19 -6
- data/lib/passtools/version.rb +1 -1
- data/spec/passtools/pass_spec.rb +14 -0
- data/spec/passtools/template_spec.rb +7 -0
- data/spec/support/passtools_helpers.rb +9 -2
- metadata +2 -2
data/README.md
CHANGED
@@ -47,6 +47,10 @@ Returns all templates associated with user specified by the api_key
|
|
47
47
|
|
48
48
|
Returns detail information for individual template
|
49
49
|
|
50
|
+
`Passtools::Template.delete(template_id)`
|
51
|
+
|
52
|
+
Deletes a template from the user's account
|
53
|
+
|
50
54
|
`Passtools::Pass.list`
|
51
55
|
|
52
56
|
Returns list of all Passes associated with user
|
@@ -69,6 +73,14 @@ Updates pass data
|
|
69
73
|
Downloads Pass to the directory named by the 'download_dir'
|
70
74
|
configuration value. Passes are named 'PassToolsPass.pkpass'
|
71
75
|
|
76
|
+
`Passtools::Pass.delete(pass_id)`
|
77
|
+
|
78
|
+
Delete pass from user's account
|
79
|
+
|
80
|
+
`Passtools::Pass.push(pass_id)`
|
81
|
+
|
82
|
+
Push pass changes to all devices that have the pass installed
|
83
|
+
|
72
84
|
## Example Code
|
73
85
|
|
74
86
|
Refer to the [PassTools API wiki](https://github.com/tello/passtools-api/wiki/Methods) for more information about the data returned. Generally you are most likely to be interested in data from the fieldsModel key of the Template detail data.
|
@@ -130,6 +142,9 @@ returns a templated Pass instance that has the same accessors as above.
|
|
130
142
|
This instance can be persisted with the #create method. Once it
|
131
143
|
persisted, further changes must be persisted with the #update method
|
132
144
|
|
145
|
+
Each Pass or Template instance has access to the API methods that make sense
|
146
|
+
for an single object(eg. create, update, push, delete).
|
147
|
+
|
133
148
|
## Usage
|
134
149
|
|
135
150
|
Given the same example as above you could:
|
data/lib/passtools/pass.rb
CHANGED
@@ -4,17 +4,17 @@ module Passtools
|
|
4
4
|
attr_accessor :raw_data
|
5
5
|
|
6
6
|
def self.list
|
7
|
-
get("/pass")
|
7
|
+
get("/pass")
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.list_by_template(template_id)
|
11
11
|
#TODO not implemented in API yet
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.show(pass_id)
|
15
|
-
get("/pass/#{pass_id}")
|
14
|
+
def self.show(pass_id, params = {})
|
15
|
+
get("/pass/#{pass_id}", params)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def self.create(template_id,data)
|
19
19
|
json = MultiJson.dump(data)
|
20
20
|
post("/pass/#{template_id}", {:json => json } )
|
@@ -29,6 +29,14 @@ module Passtools
|
|
29
29
|
download_file("/pass/#{pass_id}/download", 'PassToolsPass.pkpass')
|
30
30
|
end
|
31
31
|
|
32
|
+
def self.push(pass_id)
|
33
|
+
put("/pass/#{pass_id}/push")
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.delete(pass_id)
|
37
|
+
delete_request("/pass/#{pass_id}")
|
38
|
+
end
|
39
|
+
|
32
40
|
def self.build_from_current(pass_id)
|
33
41
|
begin
|
34
42
|
response = show(pass_id)
|
@@ -76,10 +84,27 @@ module Passtools
|
|
76
84
|
self.raw_data = response if new_id
|
77
85
|
end
|
78
86
|
|
79
|
-
def update
|
87
|
+
def update
|
80
88
|
return false unless self.id
|
81
89
|
self.class.update(id, @raw_data["passFields"])
|
82
90
|
end
|
83
91
|
|
92
|
+
def push
|
93
|
+
return false unless self.id
|
94
|
+
self.class.push(id)
|
95
|
+
end
|
96
|
+
|
97
|
+
def delete
|
98
|
+
return false unless self.id
|
99
|
+
response = self.class.delete(id)
|
100
|
+
self.raw_data['id'] = nil if response['Status'] == 'Deleted'
|
101
|
+
response
|
102
|
+
end
|
103
|
+
|
104
|
+
def download
|
105
|
+
return false unless self.id
|
106
|
+
self.class.download(self.id)
|
107
|
+
end
|
108
|
+
|
84
109
|
end
|
85
110
|
end
|
data/lib/passtools/request.rb
CHANGED
@@ -4,7 +4,7 @@ module Passtools
|
|
4
4
|
def get(path, params = {})
|
5
5
|
url = construct_url(path)
|
6
6
|
params.merge!(:api_key => Passtools.api_key)
|
7
|
-
response = RestClient.get(url, :params => params)
|
7
|
+
response = RestClient.get(url, headers.merge(:params => params))
|
8
8
|
MultiJson.load(response)
|
9
9
|
end
|
10
10
|
|
@@ -13,21 +13,28 @@ module Passtools
|
|
13
13
|
raise "Download directory is not defined or does not exist" unless filepath.exist?
|
14
14
|
url = construct_url(path)
|
15
15
|
params = {:api_key => Passtools.api_key}
|
16
|
-
response = RestClient.get(url, :params => params)
|
16
|
+
response = RestClient.get(url, headers.merge(:params => params))
|
17
17
|
File.open(filepath.join(filename), 'w') {|f| f.write(response) }
|
18
18
|
end
|
19
19
|
|
20
20
|
def post(path, params = {})
|
21
21
|
url = construct_url(path)
|
22
22
|
params.merge!(:api_key => Passtools.api_key )
|
23
|
-
response = RestClient.post(url, params, :multipart => true )
|
23
|
+
response = RestClient.post(url, params, headers.merge(:multipart => true) )
|
24
24
|
MultiJson.load(response)
|
25
25
|
end
|
26
26
|
|
27
27
|
def put(path, params = {})
|
28
28
|
url = construct_url(path)
|
29
29
|
params.merge!(:api_key => Passtools.api_key )
|
30
|
-
response = RestClient.put(url, params, :multipart => true )
|
30
|
+
response = RestClient.put(url, params, headers.merge(:multipart => true) )
|
31
|
+
MultiJson.load(response)
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete_request(path, params = {})
|
35
|
+
url = construct_url(path)
|
36
|
+
params.merge!(:api_key => Passtools.api_key )
|
37
|
+
response = RestClient.delete(url, headers.merge(:params => params))
|
31
38
|
MultiJson.load(response)
|
32
39
|
end
|
33
40
|
|
@@ -36,6 +43,11 @@ module Passtools
|
|
36
43
|
Passtools.url + path
|
37
44
|
end
|
38
45
|
|
46
|
+
def headers
|
47
|
+
{ :user_agent => "passtools-gem-#{Passtools::VERSION}",
|
48
|
+
:accept => :json }
|
49
|
+
end
|
50
|
+
|
39
51
|
end
|
40
52
|
end
|
41
53
|
|
data/lib/passtools/template.rb
CHANGED
@@ -3,14 +3,18 @@ module Passtools
|
|
3
3
|
extend Request
|
4
4
|
attr_accessor :raw_data
|
5
5
|
|
6
|
-
def self.list
|
7
|
-
get("/template/headers")
|
6
|
+
def self.list(params={})
|
7
|
+
get("/template/headers", params)
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.show(template_id)
|
11
11
|
get("/template/#{template_id}")
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.delete(template_id)
|
15
|
+
delete_request("/template/#{template_id}")
|
16
|
+
end
|
17
|
+
|
14
18
|
def self.build_from_current(template_id)
|
15
19
|
begin
|
16
20
|
response = show(template_id)
|
@@ -40,6 +44,19 @@ module Passtools
|
|
40
44
|
fetch_from_raw('fieldsModel')
|
41
45
|
end
|
42
46
|
|
47
|
+
def delete
|
48
|
+
return false unless self.id
|
49
|
+
response = self.class.delete_pass(id)
|
50
|
+
self.raw_data['id'] = nil if response['Status'] == 'Deleted'
|
51
|
+
response
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid?
|
55
|
+
@raw_data.has_key?('fieldsModel')
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
43
60
|
def fetch_from_raw(*args)
|
44
61
|
data = @raw_data
|
45
62
|
res = nil
|
@@ -47,9 +64,5 @@ module Passtools
|
|
47
64
|
res
|
48
65
|
end
|
49
66
|
|
50
|
-
def valid?
|
51
|
-
@raw_data.has_key?('fieldsModel')
|
52
|
-
end
|
53
|
-
|
54
67
|
end
|
55
68
|
end
|
data/lib/passtools/version.rb
CHANGED
data/spec/passtools/pass_spec.rb
CHANGED
@@ -45,6 +45,20 @@ describe 'Pass' do
|
|
45
45
|
stub.should have_been_requested
|
46
46
|
end
|
47
47
|
|
48
|
+
it "calls Passtools API to push Pass" do
|
49
|
+
stub = stub_write(:put, "http://foobar.com/pass/55/push")
|
50
|
+
|
51
|
+
Passtools::Pass.push(55)
|
52
|
+
stub.should have_been_requested
|
53
|
+
end
|
54
|
+
|
55
|
+
it "calls Passtools API to delete Pass" do
|
56
|
+
stub = stub_delete("http://foobar.com/pass/55" )
|
57
|
+
|
58
|
+
Passtools::Pass.delete(55)
|
59
|
+
stub.should have_been_requested
|
60
|
+
end
|
61
|
+
|
48
62
|
it "raises descriptive error if directory does not exist when downloading" do
|
49
63
|
Passtools.configure(:download_dir => "/asdfasdfasfd")
|
50
64
|
expect {Passtools::Pass.download(55)}.to raise_error(RuntimeError, /Download directory is not defined or does not exist/)
|
@@ -21,6 +21,13 @@ describe 'Template' do
|
|
21
21
|
stub.should have_been_requested
|
22
22
|
end
|
23
23
|
|
24
|
+
it "calls Passtools API to delete template" do
|
25
|
+
stub = stub_delete("http://foobar.com/template/55" )
|
26
|
+
|
27
|
+
Passtools::Template.delete(55)
|
28
|
+
stub.should have_been_requested
|
29
|
+
end
|
30
|
+
|
24
31
|
context "The Template instance" do
|
25
32
|
context 'when built from succesful api call' do
|
26
33
|
before(:all) do
|
@@ -6,13 +6,20 @@ module PasstoolsHelpers
|
|
6
6
|
to_return(:body => MultiJson.dump(body))
|
7
7
|
end
|
8
8
|
|
9
|
-
def stub_write(request_type, url, json)
|
9
|
+
def stub_write(request_type, url, json = nil)
|
10
|
+
body = {:api_key => 'i_am_an_api_key'}
|
11
|
+
body.merge!(:json => json) if json
|
10
12
|
stub = stub_request(request_type, url).
|
11
|
-
with(:body =>
|
13
|
+
with(:body => body,
|
12
14
|
:headers => {'Content-Type'=>'application/x-www-form-urlencoded', 'Multipart'=>'true'}).
|
13
15
|
to_return(:body => "{}")
|
14
16
|
end
|
15
17
|
|
18
|
+
def stub_delete(url,body={})
|
19
|
+
stub_request(:delete, url).
|
20
|
+
with(:query => {:api_key => 'i_am_an_api_key'}).
|
21
|
+
to_return(:body => MultiJson.dump(body))
|
22
|
+
end
|
16
23
|
|
17
24
|
def stub_error(url, error)
|
18
25
|
stub_request(:get, url).
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: passtools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|