pin_up 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/Gemfile +17 -0
  4. data/Gemfile.lock +99 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +19 -0
  7. data/Rakefile +48 -0
  8. data/VERSION +1 -0
  9. data/lib/pin_up.rb +8 -0
  10. data/lib/pin_up/base.rb +54 -0
  11. data/lib/pin_up/card.rb +8 -0
  12. data/lib/pin_up/charge.rb +23 -0
  13. data/lib/pin_up/customer.rb +30 -0
  14. data/lib/pin_up/refund.rb +13 -0
  15. data/pin_up.gemspec +109 -0
  16. data/spec/base_spec.rb +30 -0
  17. data/spec/cards_spec.rb +12 -0
  18. data/spec/charges_spec.rb +28 -0
  19. data/spec/customers_spec.rb +36 -0
  20. data/spec/refund_spec.rb +25 -0
  21. data/spec/spec_helper.rb +29 -0
  22. data/spec/vcr/Base/should_list_succesfully_connect_to_Pin.yml +73 -0
  23. data/spec/vcr/Card/should_create_a_card_and_respond_with_the_card_detail_from_pin.yml +53 -0
  24. data/spec/vcr/Charge/should_create_a_charge_given_details.yml +52 -0
  25. data/spec/vcr/Charge/should_list_charges_in_Pin.yml +96 -0
  26. data/spec/vcr/Charge/should_not_show_a_charge_if_end_date_is_out_of_range.yml +50 -0
  27. data/spec/vcr/Charge/should_show_a_charge_given_a_search_term.yml +58 -0
  28. data/spec/vcr/Charge/should_show_a_charge_given_a_token.yml +53 -0
  29. data/spec/vcr/Customer/should_create_a_customer_given_a_card_token_customer_email.yml +101 -0
  30. data/spec/vcr/Customer/should_create_a_customer_given_an_email_and_card_details.yml +51 -0
  31. data/spec/vcr/Customer/should_list_charges_to_a_customer_given_a_token.yml +53 -0
  32. data/spec/vcr/Customer/should_list_customers.yml +65 -0
  33. data/spec/vcr/Customer/should_raise_an_error_if_an_attribute_is_missing_in_the_card_hash.yml +50 -0
  34. data/spec/vcr/Customer/should_show_a_customer_given_a_token.yml +51 -0
  35. data/spec/vcr/Customer/should_update_a_customer_given_a_token_and_details_to_update.yml +51 -0
  36. data/spec/vcr/Refund/should_create_a_refund_for_a_given_amount_and_charge.yml +50 -0
  37. data/spec/vcr/Refund/should_create_a_refund_for_the_entire_amount_of_a_charge_if_no_amount_given.yml +50 -0
  38. data/spec/vcr/Refund/should_list_all_refunds_made_to_a_charge_given_a_token.yml +50 -0
  39. data/spec/vcr/Refund/should_return_nothing_if_looking_for_a_charge_without_a_refund.yml +50 -0
  40. data/test/helper.rb +18 -0
  41. data/test/test_pin-payments.rb +7 -0
  42. metadata +239 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e23144942115aaf7f8c623b9c475189fe58cf374
4
+ data.tar.gz: a3508a238afd927a970a92c3ba9bdc89aace64bd
5
+ SHA512:
6
+ metadata.gz: f66ec5b5437b7c3c69a3c772acb7ddb873f5d944aa9451957b455a984d739c1d08785fc9dc87179f8ab013644692cc181759e53fa874c5d0c34c6087e9692d85
7
+ data.tar.gz: 6f4f7a090b63d00af62bb83d838a13153b916bcea92a704b38ffc0d42c8799d3c9860deaa793baa4cef2ab54deb7f7dfc51102ff4ed6c2d450bb69bb21bad2bb
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "httparty"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "rspec"
12
+ gem "httparty"
13
+ gem "jeweler", "~> 1.8.4"
14
+ gem "simplecov", ">= 0"
15
+ gem "webmock"
16
+ gem "vcr"
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,99 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.0)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.5)
11
+ atomic (1.1.10)
12
+ builder (3.2.2)
13
+ crack (0.4.0)
14
+ safe_yaml (~> 0.9.0)
15
+ diff-lcs (1.2.4)
16
+ faraday (0.8.7)
17
+ multipart-post (~> 1.1)
18
+ git (1.2.5)
19
+ github_api (0.10.1)
20
+ addressable
21
+ faraday (~> 0.8.1)
22
+ hashie (>= 1.2)
23
+ multi_json (~> 1.4)
24
+ nokogiri (~> 1.5.2)
25
+ oauth2
26
+ hashie (2.0.5)
27
+ highline (1.6.19)
28
+ httparty (0.11.0)
29
+ multi_json (~> 1.0)
30
+ multi_xml (>= 0.5.2)
31
+ httpauth (0.2.0)
32
+ i18n (0.6.4)
33
+ jeweler (1.8.5)
34
+ builder
35
+ bundler (~> 1.0)
36
+ git (>= 1.2.5)
37
+ github_api (>= 0.8.1)
38
+ highline (>= 1.6.15)
39
+ nokogiri (= 1.5.10)
40
+ rake
41
+ rdoc
42
+ json (1.8.0)
43
+ jwt (0.1.8)
44
+ multi_json (>= 1.5)
45
+ minitest (4.7.5)
46
+ multi_json (1.7.7)
47
+ multi_xml (0.5.4)
48
+ multipart-post (1.2.0)
49
+ nokogiri (1.5.10)
50
+ oauth2 (0.9.2)
51
+ faraday (~> 0.8)
52
+ httpauth (~> 0.2)
53
+ jwt (~> 0.1.4)
54
+ multi_json (~> 1.0)
55
+ multi_xml (~> 0.5)
56
+ rack (~> 1.2)
57
+ rack (1.5.2)
58
+ rake (10.1.0)
59
+ rdoc (3.12.2)
60
+ json (~> 1.4)
61
+ rspec (2.13.0)
62
+ rspec-core (~> 2.13.0)
63
+ rspec-expectations (~> 2.13.0)
64
+ rspec-mocks (~> 2.13.0)
65
+ rspec-core (2.13.1)
66
+ rspec-expectations (2.13.0)
67
+ diff-lcs (>= 1.1.3, < 2.0)
68
+ rspec-mocks (2.13.1)
69
+ safe_yaml (0.9.3)
70
+ shoulda (3.5.0)
71
+ shoulda-context (~> 1.0, >= 1.0.1)
72
+ shoulda-matchers (>= 1.4.1, < 3.0)
73
+ shoulda-context (1.1.4)
74
+ shoulda-matchers (2.2.0)
75
+ activesupport (>= 3.0.0)
76
+ simplecov (0.7.1)
77
+ multi_json (~> 1.0)
78
+ simplecov-html (~> 0.7.1)
79
+ simplecov-html (0.7.1)
80
+ thread_safe (0.1.0)
81
+ atomic
82
+ tzinfo (0.3.37)
83
+ vcr (2.5.0)
84
+ webmock (1.12.3)
85
+ addressable (>= 2.2.7)
86
+ crack (>= 0.3.2)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ httparty
93
+ jeweler (~> 1.8.4)
94
+ rdoc (~> 3.12)
95
+ rspec
96
+ shoulda
97
+ simplecov
98
+ vcr
99
+ webmock
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Daniel Nitsikopoulos
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.md ADDED
@@ -0,0 +1,19 @@
1
+ = pin_up
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to pin_up
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 Daniel Nitsikopoulos. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "pin_up"
18
+ gem.homepage = "http://github.com/dNitza/pin_up"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A Ruby gem wrapper for the pin-payments (pin.net.au) API}
21
+ gem.description = %Q{A Ruby gem wrapper for the pin-payments (pin.net.au) API}
22
+ gem.email = "dnitza@gmail.com"
23
+ gem.authors = ["Daniel Nitsikopoulos"]
24
+ # dependencies defined in Gemfile
25
+ gem.add_dependency "httparty"
26
+ gem.add_development_dependency "webmock"
27
+ gem.add_development_dependency "vcr"
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rake/testtask'
32
+ Rake::TestTask.new(:test) do |test|
33
+ test.libs << 'lib' << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+
38
+ task :default => :test
39
+
40
+ require 'rdoc/task'
41
+ Rake::RDocTask.new do |rdoc|
42
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "pin_up #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/pin_up.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ require 'pin_up/base.rb'
5
+ require 'pin_up/card.rb'
6
+ require 'pin_up/charge.rb'
7
+ require 'pin_up/customer.rb'
8
+ require 'pin_up/refund.rb'
@@ -0,0 +1,54 @@
1
+ module Pin
2
+ class Base
3
+ include HTTParty
4
+
5
+ def initialize(key: "", env: :live)
6
+ @key = key
7
+ env = env.to_sym
8
+ @@auth = {username: key, password: ''}
9
+ @@base_url = if env == :live
10
+ "https://api.pin.net.au/1/"
11
+ elsif env == :test
12
+ "https://test-api.pin.net.au/1/"
13
+ else
14
+ raise "'env' option must be :live or :test. Leave blank for live payments"
15
+ end
16
+ end
17
+
18
+ def key
19
+ @key
20
+ end
21
+
22
+ def uri
23
+ @@base_url
24
+ end
25
+
26
+ protected
27
+
28
+ def self.auth_get(url, token: nil)
29
+ HTTParty.get("#{@@base_url}#{url}", basic_auth: @@auth)
30
+ end
31
+
32
+ def self.auth_post(url, options = {})
33
+ HTTParty.post("#{@@base_url}#{url}", body: options, basic_auth: @@auth)
34
+ end
35
+
36
+ def self.auth_put(url, options = {})
37
+ HTTParty.put("#{@@base_url}#{url}", body: options, basic_auth: @@auth)
38
+ end
39
+
40
+ def self.build_response(response)
41
+ response.parsed_response['response']
42
+ end
43
+
44
+ def self.build_collection_response(response)
45
+ models = []
46
+ if response.code == 200
47
+ response.parsed_response['response'].each do |model|
48
+ models << model
49
+ end
50
+ end
51
+ models
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,8 @@
1
+ module Pin
2
+ class Card < Base
3
+
4
+ def self.create(options)
5
+ build_response(auth_post('cards', options))
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ module Pin
2
+ class Charges < Base
3
+ def self.all
4
+ build_response(auth_get('charges'))
5
+ end
6
+
7
+ def self.find(token)
8
+ build_response(auth_get("charges/#{token}"))
9
+ end
10
+
11
+ def self.search(options = {})
12
+ term = ""
13
+ options.each do |key, option|
14
+ term += "#{key.to_s}=#{URI::encode(option)}&"
15
+ end
16
+ build_response(auth_get("charges/search?#{term}"))
17
+ end
18
+
19
+ def self.create(options = {})
20
+ build_response(auth_post("charges", options))
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ module Pin
2
+ class Customer < Base
3
+
4
+ def self.all
5
+ build_collection_response(auth_get('customers'))
6
+ end
7
+
8
+ def self.create(email, card)
9
+ options = if card.respond_to?(:to_hash)
10
+ {card: card.to_hash}
11
+ else
12
+ {card_token: card}
13
+ end.merge(email: email)
14
+
15
+ build_response(auth_post('customers', options))
16
+ end
17
+
18
+ def self.find(token)
19
+ build_response(auth_get("customers/#{token}"))
20
+ end
21
+
22
+ def self.update(token, options = {})
23
+ build_response(auth_put("customers/#{token}", options))
24
+ end
25
+
26
+ def self.charges(token)
27
+ build_collection_response(auth_get("customers/#{token}/charges"))
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module Pin
2
+ class Refund < Base
3
+
4
+ def self.find(token)
5
+ build_collection_response(auth_get("charges/#{token}/refunds"))
6
+ end
7
+
8
+ def self.create(token, amount = nil)
9
+ options = {amount: amount}
10
+ build_response(auth_post("charges/#{token}/refunds", options))
11
+ end
12
+ end
13
+ end
data/pin_up.gemspec ADDED
@@ -0,0 +1,109 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
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 = "pin_up"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Daniel Nitsikopoulos"]
12
+ s.date = "2013-07-05"
13
+ s.description = "A Ruby gem wrapper for the pin-payments (pin.net.au) API"
14
+ s.email = "dnitza@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/pin_up.rb",
28
+ "lib/pin_up/base.rb",
29
+ "lib/pin_up/card.rb",
30
+ "lib/pin_up/charge.rb",
31
+ "lib/pin_up/customer.rb",
32
+ "lib/pin_up/refund.rb",
33
+ "pin_up.gemspec",
34
+ "spec/base_spec.rb",
35
+ "spec/cards_spec.rb",
36
+ "spec/charges_spec.rb",
37
+ "spec/customers_spec.rb",
38
+ "spec/refund_spec.rb",
39
+ "spec/spec_helper.rb",
40
+ "spec/vcr/Base/should_list_succesfully_connect_to_Pin.yml",
41
+ "spec/vcr/Card/should_create_a_card_and_respond_with_the_card_detail_from_pin.yml",
42
+ "spec/vcr/Charge/should_create_a_charge_given_details.yml",
43
+ "spec/vcr/Charge/should_list_charges_in_Pin.yml",
44
+ "spec/vcr/Charge/should_not_show_a_charge_if_end_date_is_out_of_range.yml",
45
+ "spec/vcr/Charge/should_show_a_charge_given_a_search_term.yml",
46
+ "spec/vcr/Charge/should_show_a_charge_given_a_token.yml",
47
+ "spec/vcr/Customer/should_create_a_customer_given_a_card_token_customer_email.yml",
48
+ "spec/vcr/Customer/should_create_a_customer_given_an_email_and_card_details.yml",
49
+ "spec/vcr/Customer/should_list_charges_to_a_customer_given_a_token.yml",
50
+ "spec/vcr/Customer/should_list_customers.yml",
51
+ "spec/vcr/Customer/should_raise_an_error_if_an_attribute_is_missing_in_the_card_hash.yml",
52
+ "spec/vcr/Customer/should_show_a_customer_given_a_token.yml",
53
+ "spec/vcr/Customer/should_update_a_customer_given_a_token_and_details_to_update.yml",
54
+ "spec/vcr/Refund/should_create_a_refund_for_a_given_amount_and_charge.yml",
55
+ "spec/vcr/Refund/should_create_a_refund_for_the_entire_amount_of_a_charge_if_no_amount_given.yml",
56
+ "spec/vcr/Refund/should_list_all_refunds_made_to_a_charge_given_a_token.yml",
57
+ "spec/vcr/Refund/should_return_nothing_if_looking_for_a_charge_without_a_refund.yml",
58
+ "test/helper.rb",
59
+ "test/test_pin-payments.rb"
60
+ ]
61
+ s.homepage = "http://github.com/dNitza/pin_up"
62
+ s.licenses = ["MIT"]
63
+ s.require_paths = ["lib"]
64
+ s.rubygems_version = "2.0.3"
65
+ s.summary = "A Ruby gem wrapper for the pin-payments (pin.net.au) API"
66
+
67
+ if s.respond_to? :specification_version then
68
+ s.specification_version = 4
69
+
70
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
71
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
72
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
73
+ s.add_development_dependency(%q<rspec>, [">= 0"])
74
+ s.add_development_dependency(%q<httparty>, [">= 0"])
75
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
76
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
77
+ s.add_development_dependency(%q<webmock>, [">= 0"])
78
+ s.add_development_dependency(%q<vcr>, [">= 0"])
79
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
80
+ s.add_development_dependency(%q<webmock>, [">= 0"])
81
+ s.add_development_dependency(%q<vcr>, [">= 0"])
82
+ else
83
+ s.add_dependency(%q<shoulda>, [">= 0"])
84
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
85
+ s.add_dependency(%q<rspec>, [">= 0"])
86
+ s.add_dependency(%q<httparty>, [">= 0"])
87
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
88
+ s.add_dependency(%q<simplecov>, [">= 0"])
89
+ s.add_dependency(%q<webmock>, [">= 0"])
90
+ s.add_dependency(%q<vcr>, [">= 0"])
91
+ s.add_dependency(%q<httparty>, [">= 0"])
92
+ s.add_dependency(%q<webmock>, [">= 0"])
93
+ s.add_dependency(%q<vcr>, [">= 0"])
94
+ end
95
+ else
96
+ s.add_dependency(%q<shoulda>, [">= 0"])
97
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
98
+ s.add_dependency(%q<rspec>, [">= 0"])
99
+ s.add_dependency(%q<httparty>, [">= 0"])
100
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
101
+ s.add_dependency(%q<simplecov>, [">= 0"])
102
+ s.add_dependency(%q<webmock>, [">= 0"])
103
+ s.add_dependency(%q<vcr>, [">= 0"])
104
+ s.add_dependency(%q<httparty>, [">= 0"])
105
+ s.add_dependency(%q<webmock>, [">= 0"])
106
+ s.add_dependency(%q<vcr>, [">= 0"])
107
+ end
108
+ end
109
+