zipmark 0.0.1.beta.1 → 0.0.1.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/zipmark/adapters/httparty_adapter.rb +3 -0
- data/lib/zipmark/adapters/httpclient_adapter.rb +1 -1
- data/lib/zipmark/callback.rb +28 -7
- data/lib/zipmark/client.rb +12 -4
- data/lib/zipmark/entity.rb +4 -0
- data/lib/zipmark/input.rb +17 -1
- data/lib/zipmark/version.rb +1 -1
- metadata +2 -2
@@ -4,7 +4,7 @@ module Zipmark
|
|
4
4
|
begin
|
5
5
|
require 'httpclient'
|
6
6
|
rescue LoadError
|
7
|
-
puts 'You must install httpclient to use Zipmark::Adapters::
|
7
|
+
puts 'You must install httpclient to use Zipmark::Adapters::HTTPClientAdapter '
|
8
8
|
end
|
9
9
|
|
10
10
|
attr_accessor :username, :password, :production
|
data/lib/zipmark/callback.rb
CHANGED
@@ -1,17 +1,33 @@
|
|
1
|
+
require'base64'
|
2
|
+
require 'openssl'
|
3
|
+
|
1
4
|
module Zipmark
|
2
5
|
class Callback
|
3
|
-
attr_accessor :request, :errors
|
6
|
+
attr_accessor :request, :errors, :client
|
4
7
|
|
5
8
|
def initialize(request, options = {})
|
6
9
|
raise ArgumentError, "Request cannot be nil" unless request
|
7
10
|
@request = request
|
8
11
|
@errors = {}
|
12
|
+
@client = options[:client]
|
9
13
|
end
|
10
14
|
|
11
15
|
def body
|
12
16
|
@request.raw_post
|
13
17
|
end
|
14
18
|
|
19
|
+
def identifier
|
20
|
+
client.identifier if client
|
21
|
+
end
|
22
|
+
|
23
|
+
def application_identifier
|
24
|
+
client.adapter.username if client
|
25
|
+
end
|
26
|
+
|
27
|
+
def secret
|
28
|
+
client.adapter.password if client
|
29
|
+
end
|
30
|
+
|
15
31
|
def event
|
16
32
|
raise "unimplemented"
|
17
33
|
end
|
@@ -37,7 +53,12 @@ module Zipmark
|
|
37
53
|
end
|
38
54
|
|
39
55
|
def date_within_range?
|
40
|
-
date && date < Time.now +
|
56
|
+
date && date < Time.now + allowable_interval && date > Time.now - allowable_interval
|
57
|
+
end
|
58
|
+
|
59
|
+
def allowable_interval
|
60
|
+
# 15 minutes
|
61
|
+
15 * 60
|
41
62
|
end
|
42
63
|
|
43
64
|
def valid?
|
@@ -45,13 +66,13 @@ module Zipmark
|
|
45
66
|
end
|
46
67
|
|
47
68
|
def validate_authorization
|
48
|
-
string_to_sign = ["POST",hashed_content,'application/json',date.rfc2822,uri,
|
49
|
-
signed_string =
|
50
|
-
valid_authorization = "ZM #{
|
69
|
+
string_to_sign = ["POST",hashed_content,'application/json',date.rfc2822,uri,application_identifier].join("\n")
|
70
|
+
signed_string = Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), secret, string_to_sign))
|
71
|
+
valid_authorization = "ZM #{Base64.strict_encode64(identifier)}:#{signed_string}"
|
51
72
|
if authorization_header == valid_authorization
|
52
73
|
return true
|
53
74
|
else
|
54
|
-
|
75
|
+
errors[:authorization] = "Signature does not match."
|
55
76
|
return false
|
56
77
|
end
|
57
78
|
end
|
@@ -60,7 +81,7 @@ module Zipmark
|
|
60
81
|
if date_within_range?
|
61
82
|
return true
|
62
83
|
else
|
63
|
-
|
84
|
+
errors[:date] = "Date is not within bounds."
|
64
85
|
return false
|
65
86
|
end
|
66
87
|
end
|
data/lib/zipmark/client.rb
CHANGED
@@ -12,19 +12,23 @@ module Zipmark
|
|
12
12
|
|
13
13
|
# Public: Initialize a Zipmark Client
|
14
14
|
#
|
15
|
+
# options - Hash options used to configure the Client (default: {})
|
15
16
|
# application_id - The Identifier for your application
|
16
17
|
# application_secret - The Secret for your Application
|
17
|
-
# options - Hash options used to configure the Client (default: {})
|
18
18
|
# :adapter - The Instance of an Adapter that wraps your preferred HTTP Client
|
19
19
|
# :production - The Boolean determining if Production Mode is enabled
|
20
|
-
def initialize(
|
20
|
+
def initialize(options = {})
|
21
21
|
@adapter = options[:adapter] || Zipmark::Adapters::HTTPClientAdapter.new
|
22
22
|
adapter.production = options[:production]
|
23
|
-
adapter.username = application_id
|
24
|
-
adapter.password = application_secret
|
23
|
+
adapter.username = options[:application_id]
|
24
|
+
adapter.password = options[:application_secret]
|
25
|
+
@identifier = options[:vendor_identifier]
|
25
26
|
@resources = load_resources
|
26
27
|
end
|
27
28
|
|
29
|
+
def identifier
|
30
|
+
@identifier
|
31
|
+
end
|
28
32
|
|
29
33
|
# Public: Send a GET Request to the given API Path
|
30
34
|
#
|
@@ -56,6 +60,10 @@ module Zipmark
|
|
56
60
|
adapter.delete(path)
|
57
61
|
end
|
58
62
|
|
63
|
+
def build_callback(request)
|
64
|
+
Zipmark::Callback.new(request, :client => self)
|
65
|
+
end
|
66
|
+
|
59
67
|
def method_missing(meth, *args, &block)
|
60
68
|
@resources[meth.to_s] || raise(NoMethodError, "No resource or method: '#{meth}'")
|
61
69
|
end
|
data/lib/zipmark/entity.rb
CHANGED
@@ -10,6 +10,10 @@ module Zipmark
|
|
10
10
|
@resource_type = @attributes.delete("resource_type")
|
11
11
|
end
|
12
12
|
|
13
|
+
def inspect
|
14
|
+
"<Entity:#{object_id} #{attributes.inspect}>"
|
15
|
+
end
|
16
|
+
|
13
17
|
def method_missing(meth, *args, &block)
|
14
18
|
if meth =~ /=$/
|
15
19
|
dirty_attributes[meth.to_s.sub(/=$/, '')] = args.first
|
data/lib/zipmark/input.rb
CHANGED
@@ -1,5 +1,21 @@
|
|
1
|
+
# Plans to support the following input types:
|
2
|
+
# checkbox
|
3
|
+
# date
|
4
|
+
# datetime
|
5
|
+
# email
|
6
|
+
# month
|
7
|
+
# number
|
8
|
+
# password
|
9
|
+
# radio
|
10
|
+
# range
|
11
|
+
# search
|
12
|
+
# tel
|
13
|
+
# text
|
14
|
+
# time
|
15
|
+
# url
|
16
|
+
# week
|
1
17
|
module Zipmark
|
2
18
|
class Input
|
3
|
-
attr_accessor :type, :required, :name, :
|
19
|
+
attr_accessor :type, :required, :name, :placeholder, :value
|
4
20
|
end
|
5
21
|
end
|
data/lib/zipmark/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zipmark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.beta.
|
4
|
+
version: 0.0.1.beta.2
|
5
5
|
prerelease: 6
|
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-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Simple Client Library to connect to the Zipmark API
|
15
15
|
email: jake@zipmark.com
|