passninja-ruby 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/passninja/version.rb +1 -1
- data/lib/passninja.rb +54 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b62e7fa7e35dc0c193f7bc019713f297884cd33939a17015f69cca3a567354c7
|
4
|
+
data.tar.gz: 68512e3890cd1e63b3d7a62061e9c859c1ce606ce4bd6f01a2ac93d4e008e54d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9124fd27d4df8ff973a7a29a3c097a70db4d0fe2a3e92654126c51911b3ac0744de699e5dbcd29cceaf07e16faa95d987f0ed31279a6680b7cc91ea5b4eff625
|
7
|
+
data.tar.gz: 93d91c67ce3744c0c0032f634722b11faa26d37dc61284858b93488a6ae6537a237540e125cc9ea0ed91d9c0c26e5df6d770d811899e3fb90ff3d667fecf2ae7
|
data/lib/passninja/version.rb
CHANGED
data/lib/passninja.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "net/http"
|
2
2
|
require "json"
|
3
3
|
|
4
|
-
module
|
4
|
+
module PassNinja
|
5
5
|
class Client
|
6
6
|
def initialize(account_id, api_key)
|
7
7
|
@account_id = account_id
|
@@ -25,14 +25,20 @@ module Passninja
|
|
25
25
|
|
26
26
|
def find(pass_template_key)
|
27
27
|
uri = URI("https://api.passninja.com/v1/pass_templates/#{pass_template_key}")
|
28
|
+
puts uri
|
28
29
|
request = Net::HTTP::Get.new(uri)
|
29
|
-
request
|
30
|
+
request["X-API-KEY"] = @api_key
|
31
|
+
request["X-ACCOUNT-ID"] = @account_id
|
30
32
|
|
31
33
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
32
34
|
http.request(request)
|
33
35
|
end
|
34
36
|
|
35
|
-
|
37
|
+
begin
|
38
|
+
JSON.parse(response.body)
|
39
|
+
rescue JSON::ParserError
|
40
|
+
{ error: "Unable to parse response" }
|
41
|
+
end
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
@@ -47,45 +53,61 @@ module Passninja
|
|
47
53
|
validate_fields(pass_data, required_fields)
|
48
54
|
uri = URI("https://api.passninja.com/v1/passes")
|
49
55
|
request = Net::HTTP::Post.new(uri)
|
50
|
-
request
|
56
|
+
request["X-API-KEY"] = @api_key
|
57
|
+
request["X-ACCOUNT-ID"] = @account_id
|
51
58
|
request.content_type = "application/json"
|
52
|
-
request.body = { passType: pass_type,
|
59
|
+
request.body = { passType: pass_type, pass: pass_data }.to_json
|
53
60
|
|
54
61
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
55
62
|
http.request(request)
|
56
63
|
end
|
57
64
|
|
58
|
-
|
65
|
+
begin
|
66
|
+
JSON.parse(response.body)
|
67
|
+
rescue JSON::ParserError
|
68
|
+
{ error: "Unable to parse response" }
|
69
|
+
end
|
59
70
|
end
|
60
71
|
|
61
72
|
def find(pass_type)
|
62
|
-
uri = URI("https://api.passninja.com/v1/passes
|
73
|
+
uri = URI("https://api.passninja.com/v1/passes/#{pass_type}")
|
63
74
|
request = Net::HTTP::Get.new(uri)
|
64
|
-
request
|
75
|
+
request["X-API-KEY"] = @api_key
|
76
|
+
request["X-ACCOUNT-ID"] = @account_id
|
65
77
|
|
66
78
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
67
79
|
http.request(request)
|
68
80
|
end
|
69
81
|
|
70
|
-
|
82
|
+
begin
|
83
|
+
JSON.parse(response.body)
|
84
|
+
rescue JSON::ParserError
|
85
|
+
{ error: "Unable to parse response" }
|
86
|
+
end
|
71
87
|
end
|
72
88
|
|
73
89
|
def get(pass_type, serial_number)
|
74
90
|
uri = URI("https://api.passninja.com/v1/passes/#{pass_type}/#{serial_number}")
|
75
91
|
request = Net::HTTP::Get.new(uri)
|
76
|
-
request
|
92
|
+
request["X-API-KEY"] = @api_key
|
93
|
+
request["X-ACCOUNT-ID"] = @account_id
|
77
94
|
|
78
95
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
79
96
|
http.request(request)
|
80
97
|
end
|
81
98
|
|
82
|
-
|
99
|
+
begin
|
100
|
+
JSON.parse(response.body)
|
101
|
+
rescue JSON::ParserError
|
102
|
+
{ error: "Unable to parse response. Server response code: #{response.code}" }
|
103
|
+
end
|
83
104
|
end
|
84
105
|
|
85
106
|
def decrypt(pass_type, payload)
|
86
107
|
uri = URI("https://api.passninja.com/v1/passes/decrypt")
|
87
108
|
request = Net::HTTP::Post.new(uri)
|
88
|
-
request
|
109
|
+
request["X-API-KEY"] = @api_key
|
110
|
+
request["X-ACCOUNT-ID"] = @account_id
|
89
111
|
request.content_type = "application/json"
|
90
112
|
request.body = { passType: pass_type, payload: payload }.to_json
|
91
113
|
|
@@ -93,7 +115,11 @@ module Passninja
|
|
93
115
|
http.request(request)
|
94
116
|
end
|
95
117
|
|
96
|
-
|
118
|
+
begin
|
119
|
+
JSON.parse(response.body)
|
120
|
+
rescue JSON::ParserError
|
121
|
+
{ error: "Unable to parse response" }
|
122
|
+
end
|
97
123
|
end
|
98
124
|
|
99
125
|
def update(pass_type, serial_number, pass_data)
|
@@ -101,7 +127,8 @@ module Passninja
|
|
101
127
|
validate_fields(pass_data, required_fields)
|
102
128
|
uri = URI("https://api.passninja.com/v1/passes/#{pass_type}/#{serial_number}")
|
103
129
|
request = Net::HTTP::Put.new(uri)
|
104
|
-
request
|
130
|
+
request["X-API-KEY"] = @api_key
|
131
|
+
request["X-ACCOUNT-ID"] = @account_id
|
105
132
|
request.content_type = "application/json"
|
106
133
|
request.body = { passData: pass_data }.to_json
|
107
134
|
|
@@ -109,13 +136,18 @@ module Passninja
|
|
109
136
|
http.request(request)
|
110
137
|
end
|
111
138
|
|
112
|
-
|
139
|
+
begin
|
140
|
+
JSON.parse(response.body)
|
141
|
+
rescue JSON::ParserError
|
142
|
+
{ error: "Unable to parse response" }
|
143
|
+
end
|
113
144
|
end
|
114
145
|
|
115
146
|
def delete(pass_type, serial_number)
|
116
147
|
uri = URI("https://api.passninja.com/v1/passes/#{pass_type}/#{serial_number}")
|
117
148
|
request = Net::HTTP::Delete.new(uri)
|
118
|
-
request
|
149
|
+
request["X-API-KEY"] = @api_key
|
150
|
+
request["X-ACCOUNT-ID"] = @account_id
|
119
151
|
|
120
152
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
121
153
|
http.request(request)
|
@@ -127,19 +159,21 @@ module Passninja
|
|
127
159
|
private
|
128
160
|
|
129
161
|
def fetch_required_keys_set(pass_type)
|
130
|
-
uri = URI("https://api.passninja.com/v1/
|
162
|
+
uri = URI("https://api.passninja.com/v1/passtypes/keys/#{pass_type}")
|
163
|
+
|
131
164
|
request = Net::HTTP::Get.new(uri)
|
132
|
-
request
|
165
|
+
request["X-API-KEY"] = @api_key
|
166
|
+
request["X-ACCOUNT-ID"] = @account_id
|
133
167
|
|
134
168
|
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
135
169
|
http.request(request)
|
136
170
|
end
|
137
171
|
|
138
|
-
JSON.parse(response.body)["
|
172
|
+
JSON.parse(response.body)["keys"]
|
139
173
|
end
|
140
174
|
|
141
175
|
def validate_fields(fields, required_fields)
|
142
|
-
missing_fields = required_fields - fields.keys
|
176
|
+
missing_fields = required_fields.map(&:to_sym) - fields.keys.map(&:to_sym)
|
143
177
|
unless missing_fields.empty?
|
144
178
|
raise ArgumentError, "Missing required fields: #{missing_fields.join(', ')}"
|
145
179
|
end
|