hashrocket-mousetrap 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +6 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +7 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/mousetrap.rb +17 -0
- data/lib/mousetrap/customer.rb +11 -0
- data/lib/mousetrap/resource.rb +15 -0
- data/mousetrap.gemspec +65 -0
- data/spec/integration/settings.example.yml +4 -0
- data/spec/integration/smoke_test.rb +36 -0
- data/spec/mousetrap/customer_spec.rb +19 -0
- data/spec/mousetrap/resource_spec.rb +33 -0
- data/spec/mousetrap_spec.rb +17 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +27 -0
- metadata +94 -0
data/.document
ADDED
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jon Larkowski
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "mousetrap"
|
8
|
+
gem.summary = %Q{CheddarGetter API Client in Ruby}
|
9
|
+
gem.description = %Q{CheddarGetter API Client in Ruby}
|
10
|
+
gem.email = "jonlarkowski@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/l4rk/mousetrap"
|
12
|
+
gem.authors = ["Jon Larkowski", "Sandro Turriate"]
|
13
|
+
gem.add_development_dependency "rspec", '>= 1.2.8'
|
14
|
+
gem.add_dependency 'httparty', '>= 0.4.4'
|
15
|
+
end
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'spec/rake/spectask'
|
21
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
22
|
+
spec.spec_opts = ['--options', 'spec/spec.opts']
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
if File.exist?('VERSION')
|
40
|
+
version = File.read('VERSION')
|
41
|
+
else
|
42
|
+
version = ""
|
43
|
+
end
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "mousetrap #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/lib/mousetrap.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
begin; require 'rubygems'; rescue LoadError; end
|
4
|
+
require 'httparty'
|
5
|
+
|
6
|
+
module Mousetrap
|
7
|
+
autoload(:Resource, 'mousetrap/resource')
|
8
|
+
autoload(:Customer, 'mousetrap/customer')
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :product_code
|
12
|
+
|
13
|
+
def authenticate(user, password)
|
14
|
+
Resource.basic_auth user, password
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Mousetrap
|
2
|
+
class Resource
|
3
|
+
include HTTParty
|
4
|
+
headers 'User-Agent' => 'Mousetrap Ruby Client'
|
5
|
+
base_uri 'https://cheddargetter.com'
|
6
|
+
|
7
|
+
def self.get_resources(resource)
|
8
|
+
get "/xml/#{resource}/get/productCode/#{Mousetrap.product_code}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.post_resource(resource, action, hash)
|
12
|
+
post "/xml/#{resource}/#{action}/productCode/#{Mousetrap.product_code}", :body => hash
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/mousetrap.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mousetrap}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jon Larkowski", "Sandro Turriate"]
|
12
|
+
s.date = %q{2009-08-25}
|
13
|
+
s.description = %q{CheddarGetter API Client in Ruby}
|
14
|
+
s.email = %q{jonlarkowski@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.textile"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"MIT-LICENSE",
|
22
|
+
"README.textile",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"lib/mousetrap.rb",
|
26
|
+
"lib/mousetrap/customer.rb",
|
27
|
+
"lib/mousetrap/resource.rb",
|
28
|
+
"mousetrap.gemspec",
|
29
|
+
"spec/integration/settings.example.yml",
|
30
|
+
"spec/integration/smoke_test.rb",
|
31
|
+
"spec/mousetrap/customer_spec.rb",
|
32
|
+
"spec/mousetrap/resource_spec.rb",
|
33
|
+
"spec/mousetrap_spec.rb",
|
34
|
+
"spec/spec.opts",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/l4rk/mousetrap}
|
38
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.5}
|
41
|
+
s.summary = %q{CheddarGetter API Client in Ruby}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/integration/smoke_test.rb",
|
44
|
+
"spec/mousetrap/customer_spec.rb",
|
45
|
+
"spec/mousetrap/resource_spec.rb",
|
46
|
+
"spec/mousetrap_spec.rb",
|
47
|
+
"spec/spec_helper.rb"
|
48
|
+
]
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.8"])
|
56
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.4.4"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rspec>, [">= 1.2.8"])
|
59
|
+
s.add_dependency(%q<httparty>, [">= 0.4.4"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<rspec>, [">= 1.2.8"])
|
63
|
+
s.add_dependency(%q<httparty>, [">= 0.4.4"])
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
describe "The System" do
|
5
|
+
before do
|
6
|
+
settings = YAML.load_file(File.dirname(__FILE__) + '/settings.yml')
|
7
|
+
Mousetrap.authenticate(settings['user'], settings['password'])
|
8
|
+
Mousetrap.product_code = settings['product_code']
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'Customer.all' do
|
12
|
+
puts Mousetrap::Customer.all.to_yaml
|
13
|
+
end
|
14
|
+
|
15
|
+
it "Customer.create" do
|
16
|
+
email = random_email_address
|
17
|
+
|
18
|
+
attributes = {
|
19
|
+
'code' => email,
|
20
|
+
'firstName' => 'Example',
|
21
|
+
'lastName' => 'Customer',
|
22
|
+
'email' => email,
|
23
|
+
'subscription' => {
|
24
|
+
'planCode' => 'TEST',
|
25
|
+
'ccFirstName' => 'Jon',
|
26
|
+
'ccLastName' => 'Larkowski',
|
27
|
+
'ccNumber' => '4111111111111111',
|
28
|
+
'ccExpiration' => '12-2012',
|
29
|
+
'ccZip' => '90210'
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
customer = Mousetrap::Customer.create attributes
|
34
|
+
puts customer
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Mousetrap::Customer do
|
4
|
+
subject { Mousetrap::Customer }
|
5
|
+
|
6
|
+
describe '.all' do
|
7
|
+
it 'gets customers resources' do
|
8
|
+
subject.should_receive(:get_resources).with('customers')
|
9
|
+
subject.all
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.create' do
|
14
|
+
it "creates a customer" do
|
15
|
+
subject.should_receive(:post_resource).with('customers', 'new', 'some_hash')
|
16
|
+
subject.create('some_hash')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Mousetrap::Resource do
|
4
|
+
before do
|
5
|
+
Mousetrap.product_code = 'my_product_code'
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { Mousetrap::Resource }
|
9
|
+
|
10
|
+
describe "class" do
|
11
|
+
it "sets the base URI" do
|
12
|
+
subject.default_options[:base_uri].should == 'https://cheddargetter.com'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "set the header to our client name" do
|
16
|
+
subject.headers['User-Agent'].should == 'Mousetrap Ruby Client'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".get_resources" do
|
21
|
+
it "gets /xml/<resource>/get/productCode/<my_product_code>" do
|
22
|
+
subject.should_receive(:get).with('/xml/widgets/get/productCode/my_product_code')
|
23
|
+
subject.get_resources 'widgets'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ".post_resource" do
|
28
|
+
it "posts to /xml/<resource>/<action>/productCode/<product_code>" do
|
29
|
+
subject.should_receive(:post).with('/xml/widgets/some_action/productCode/my_product_code', :body => 'some_hash')
|
30
|
+
subject.post_resource 'widgets', 'some_action', 'some_hash'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Mousetrap do
|
4
|
+
subject { Mousetrap }
|
5
|
+
|
6
|
+
it "stores product code" do
|
7
|
+
subject.product_code = 'my_product_code'
|
8
|
+
subject.product_code.should == 'my_product_code'
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#authenticate" do
|
12
|
+
it "sets basic auth based on the supplied user and password" do
|
13
|
+
Mousetrap::Resource.should_receive(:basic_auth).with('lark@example.com', 'abc123')
|
14
|
+
subject.authenticate 'lark@example.com', 'abc123'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'mousetrap'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
|
7
|
+
def random_email_address
|
8
|
+
"#{random_string}@example.com"
|
9
|
+
end
|
10
|
+
|
11
|
+
def random_string
|
12
|
+
random_alpha_string_of_length(10)
|
13
|
+
end
|
14
|
+
|
15
|
+
def random_alpha_string_of_length(length)
|
16
|
+
letters = *'a'..'z'
|
17
|
+
random_string_for_uniqueness = ''
|
18
|
+
length.times { random_string_for_uniqueness += letters[rand(letters.size - 1)]}
|
19
|
+
random_string_for_uniqueness
|
20
|
+
end
|
21
|
+
|
22
|
+
def random_number_string_of_length(length)
|
23
|
+
numbers = *'0'..'9'
|
24
|
+
random_string_for_uniqueness = ''
|
25
|
+
length.times { random_string_for_uniqueness += numbers[rand(numbers.size - 1)]}
|
26
|
+
random_string_for_uniqueness
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hashrocket-mousetrap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Larkowski
|
8
|
+
- Sandro Turriate
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-08-25 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rspec
|
18
|
+
type: :development
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.2.8
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: httparty
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.4.4
|
35
|
+
version:
|
36
|
+
description: CheddarGetter API Client in Ruby
|
37
|
+
email: jonlarkowski@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- README.textile
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- MIT-LICENSE
|
48
|
+
- README.textile
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- lib/mousetrap.rb
|
52
|
+
- lib/mousetrap/customer.rb
|
53
|
+
- lib/mousetrap/resource.rb
|
54
|
+
- mousetrap.gemspec
|
55
|
+
- spec/integration/settings.example.yml
|
56
|
+
- spec/integration/smoke_test.rb
|
57
|
+
- spec/mousetrap/customer_spec.rb
|
58
|
+
- spec/mousetrap/resource_spec.rb
|
59
|
+
- spec/mousetrap_spec.rb
|
60
|
+
- spec/spec.opts
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
has_rdoc: false
|
63
|
+
homepage: http://github.com/l4rk/mousetrap
|
64
|
+
licenses:
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options:
|
67
|
+
- --charset=UTF-8
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: "0"
|
81
|
+
version:
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.3.5
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: CheddarGetter API Client in Ruby
|
89
|
+
test_files:
|
90
|
+
- spec/integration/smoke_test.rb
|
91
|
+
- spec/mousetrap/customer_spec.rb
|
92
|
+
- spec/mousetrap/resource_spec.rb
|
93
|
+
- spec/mousetrap_spec.rb
|
94
|
+
- spec/spec_helper.rb
|