endorser-receipt 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +17 -0
- data/Rakefile +5 -0
- data/endorser-receipt.gemspec +25 -0
- data/lib/endorser/receipt/version.rb +5 -0
- data/lib/endorser/receipt.rb +63 -0
- data/spec/endorser/receipt_spec.rb +146 -0
- data/spec/spec_helper.rb +12 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54d8f35279228f390aaf5d7a4e1fa68f8f0e36ad
|
4
|
+
data.tar.gz: 0c1d4e7223a148b80184c9170720ddaa867d6b66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f570559fea509d11e7f6457250dc125d1efe5703459f2e6067b57cdd113552f94c0fcea089c598cd9bd75a4aaeb38d8f5dbeabe634435e4eceb481519ad2ca63
|
7
|
+
data.tar.gz: 5330d49e293b19f9ffba3a75fdc1202dd876862449f4384d252484377e7b4e0637fe9c65722f7639f8ee86d1580181a6f1ae1f2d251b4ac320f70a3988623717
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
endorser-receipt
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Matthew Johnston
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Endorser::Receipt
|
2
|
+
|
3
|
+
A simple signature signing library
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'endorser-receipt'
|
9
|
+
```
|
10
|
+
|
11
|
+
## Contributing
|
12
|
+
|
13
|
+
1. Fork it
|
14
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
15
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
16
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
17
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'endorser/receipt/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "endorser-receipt"
|
8
|
+
spec.version = Endorser::Receipt::VERSION
|
9
|
+
spec.authors = ["Matthew Johnston", "Graham Christensen"]
|
10
|
+
spec.email = ["warmwaffles@gmail.com", "graham@zippykid.com"]
|
11
|
+
spec.description = %q{A receipt signing library}
|
12
|
+
spec.summary = %q{A receipt signing library}
|
13
|
+
spec.homepage = "https://github.com/zippykid/endorser-receipt"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14.0"
|
24
|
+
spec.add_development_dependency "simplecov"
|
25
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "endorser/receipt/version"
|
2
|
+
|
3
|
+
module Endorser
|
4
|
+
class Receipt
|
5
|
+
attr_reader :request_method
|
6
|
+
attr_reader :headers
|
7
|
+
|
8
|
+
attr_accessor :api_key
|
9
|
+
attr_accessor :api_secret
|
10
|
+
attr_accessor :body
|
11
|
+
attr_accessor :content_type
|
12
|
+
attr_accessor :uri
|
13
|
+
attr_accessor :host
|
14
|
+
|
15
|
+
def initialize(params={})
|
16
|
+
@headers = {}
|
17
|
+
|
18
|
+
self.api_key = params.fetch(:api_key, nil)
|
19
|
+
self.api_secret = params.fetch(:api_secret, nil)
|
20
|
+
self.body = params.fetch(:body, nil)
|
21
|
+
self.content_type = params.fetch(:content_type, nil)
|
22
|
+
self.uri = params.fetch(:uri, nil)
|
23
|
+
self.host = params.fetch(:host, nil)
|
24
|
+
request_method = params.fetch(:request_method, '')
|
25
|
+
end
|
26
|
+
|
27
|
+
def request_method=(s)
|
28
|
+
@request_method = s.upcase
|
29
|
+
end
|
30
|
+
|
31
|
+
def body_md5
|
32
|
+
Digest::MD5.hexdigest(body)
|
33
|
+
end
|
34
|
+
|
35
|
+
def body_length
|
36
|
+
body.length
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
preamble + header_text
|
41
|
+
end
|
42
|
+
|
43
|
+
def preamble
|
44
|
+
text = ""
|
45
|
+
text << "%s\n" % request_method
|
46
|
+
text << "%s\n" % host
|
47
|
+
text << "%s\n" % uri
|
48
|
+
text << "%s\n" % api_key
|
49
|
+
text << "%s\n" % content_type
|
50
|
+
text << "%s\n" % body_length
|
51
|
+
text << "%s\n" % body_md5
|
52
|
+
text
|
53
|
+
end
|
54
|
+
|
55
|
+
def header_text
|
56
|
+
text = ""
|
57
|
+
headers.sort_by { |k,v| k.downcase }.each do |header, value|
|
58
|
+
text << "%s:%s\n" % [header.downcase, value]
|
59
|
+
end
|
60
|
+
text
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Endorser::Receipt do
|
4
|
+
let (:receipt) { Endorser::Receipt.new }
|
5
|
+
|
6
|
+
it { should respond_to(:api_key) }
|
7
|
+
it { should respond_to(:api_key=) }
|
8
|
+
it { should respond_to(:api_secret) }
|
9
|
+
it { should respond_to(:api_secret=) }
|
10
|
+
it { should respond_to(:body) }
|
11
|
+
it { should respond_to(:body=) }
|
12
|
+
it { should respond_to(:content_type) }
|
13
|
+
it { should respond_to(:content_type=) }
|
14
|
+
it { should respond_to(:request_method) }
|
15
|
+
it { should respond_to(:request_method=) }
|
16
|
+
it { should respond_to(:host) }
|
17
|
+
it { should respond_to(:host=) }
|
18
|
+
it { should respond_to(:uri) }
|
19
|
+
it { should respond_to(:uri=) }
|
20
|
+
it { should respond_to(:headers) }
|
21
|
+
|
22
|
+
describe '#initialize' do
|
23
|
+
context 'when a hash is passed' do
|
24
|
+
def params
|
25
|
+
{
|
26
|
+
api_key: 'set',
|
27
|
+
api_secret: 'set',
|
28
|
+
body: 'set',
|
29
|
+
content_type: 'set',
|
30
|
+
uri: 'set',
|
31
|
+
host: 'set'
|
32
|
+
}
|
33
|
+
end
|
34
|
+
subject { Endorser::Receipt.new(params) }
|
35
|
+
its(:api_key) { should eq('set') }
|
36
|
+
its(:api_secret) { should eq('set') }
|
37
|
+
its(:body) { should eq('set') }
|
38
|
+
its(:content_type) { should eq('set') }
|
39
|
+
its(:uri) { should eq('set') }
|
40
|
+
its(:host) { should eq('set') }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when nothing is passed' do
|
44
|
+
subject { Endorser::Receipt.new }
|
45
|
+
its(:api_key) { should be_nil }
|
46
|
+
its(:api_secret) { should be_nil }
|
47
|
+
its(:body) { should be_nil }
|
48
|
+
its(:content_type) { should be_nil }
|
49
|
+
its(:uri) { should be_nil }
|
50
|
+
its(:host) { should be_nil }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#request_method" do
|
55
|
+
it "upcases the method" do
|
56
|
+
receipt.request_method = 'post'
|
57
|
+
receipt.request_method.should eq('POST')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#body_md5" do
|
62
|
+
it "returns the md5 of the body" do
|
63
|
+
receipt.body = 'herro'
|
64
|
+
|
65
|
+
receipt.body_md5.should eq("18f1072de45420e57fd22ee5bd59df9e")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#body_length" do
|
70
|
+
it "returns the length of the body" do
|
71
|
+
receipt.body = 'herro'
|
72
|
+
|
73
|
+
receipt.body_length.should eq(5)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#headers" do
|
78
|
+
it "defaults to an empty hash" do
|
79
|
+
receipt.headers.should eq({})
|
80
|
+
end
|
81
|
+
|
82
|
+
it "keeps around my headers" do
|
83
|
+
receipt.headers['A-a'] = 'foo'
|
84
|
+
receipt.headers['B-b'] = 'bar'
|
85
|
+
|
86
|
+
headers = receipt.headers
|
87
|
+
|
88
|
+
headers.should eq({
|
89
|
+
'A-a' => 'foo',
|
90
|
+
'B-b' => 'bar'
|
91
|
+
})
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#preamble" do
|
96
|
+
it "incorporates all the preamble elements in a string block" do
|
97
|
+
receipt.api_key = 'abc'
|
98
|
+
receipt.body = 'foo=bar'
|
99
|
+
receipt.request_method = 'post'
|
100
|
+
receipt.host = 'http://example.com'
|
101
|
+
receipt.uri = '/123?foo=bar'
|
102
|
+
receipt.content_type = "text/json"
|
103
|
+
|
104
|
+
returned = receipt.preamble
|
105
|
+
|
106
|
+
r = ""
|
107
|
+
r << "POST\n"
|
108
|
+
r << "http://example.com\n"
|
109
|
+
r << "/123?foo=bar\n"
|
110
|
+
r << "abc\n"
|
111
|
+
r << "text/json\n"
|
112
|
+
r << "7\n"
|
113
|
+
r << "06ad47d8e64bd28de537b62ff85357c4\n"
|
114
|
+
|
115
|
+
returned.should eq(r)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "#header_test" do
|
120
|
+
it "sorts the headers alphabetically and lowercases them" do
|
121
|
+
receipt.headers['B-b'] = 'bar'
|
122
|
+
receipt.headers['A-a'] = 'foo'
|
123
|
+
|
124
|
+
headers = receipt.header_text
|
125
|
+
|
126
|
+
r = ""
|
127
|
+
r << "a-a:foo\n"
|
128
|
+
r << "b-b:bar\n"
|
129
|
+
|
130
|
+
headers.should eq(r)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "#to_s" do
|
135
|
+
it "mushes to gether the preamble and headers" do
|
136
|
+
receipt.stub(:preamble => "foo\n--\n")
|
137
|
+
receipt.stub(:header_text=> "bar\n")
|
138
|
+
|
139
|
+
returned = receipt.to_s
|
140
|
+
|
141
|
+
receipt.should have_received(:preamble)
|
142
|
+
receipt.should have_received(:header_text)
|
143
|
+
returned.should eq("foo\n--\nbar\n")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: endorser-receipt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Johnston
|
8
|
+
- Graham Christensen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.14.0
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.14.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: simplecov
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: A receipt signing library
|
71
|
+
email:
|
72
|
+
- warmwaffles@gmail.com
|
73
|
+
- graham@zippykid.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- .rspec
|
80
|
+
- .ruby-gemset
|
81
|
+
- .ruby-version
|
82
|
+
- .travis.yml
|
83
|
+
- Gemfile
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- endorser-receipt.gemspec
|
88
|
+
- lib/endorser/receipt.rb
|
89
|
+
- lib/endorser/receipt/version.rb
|
90
|
+
- spec/endorser/receipt_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
homepage: https://github.com/zippykid/endorser-receipt
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.0.6
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: A receipt signing library
|
116
|
+
test_files:
|
117
|
+
- spec/endorser/receipt_spec.rb
|
118
|
+
- spec/spec_helper.rb
|