billplz 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 396dcae8959f96089fb7475ce462ba8a48d24259
4
+ data.tar.gz: 430be52e924f8e7d167b4258de0967bea8ba0a01
5
+ SHA512:
6
+ metadata.gz: e02c0c88a730d1f9c311831e77c7706a5231b23e37c75335efab7388a3bca22fa3e6930f8bac98ffd561c5da5d66a5c281d3e24bf98698e93158c60da5ccd156
7
+ data.tar.gz: db53f6c06997177a343e0722c342f59e495607ca8d687a7dadfcad719eb2d0cb167f52c1b66be19c293aa72806139147567e320dbd81710f560e5583c9add265
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at sy4mil@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in billplz.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Syamil MJ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # Billplz
2
+
3
+ [![Circle CI](https://circleci.com/gh/syamilmj/billplz.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/syamilmj/billplz)
4
+
5
+ An abstraction library to interface with the [Billplz API](https://www.billplz.com/api)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'billplz'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install billplz
22
+
23
+ ## Usage
24
+
25
+ **Configuration**
26
+
27
+ You may store your Billplz configuration during runtime:
28
+
29
+ ```ruby
30
+ # config/initializers/billplz.rb
31
+ Billplz.configure do |config|
32
+ config.api_key = ENV['BILLPLZ_API_KEY']
33
+ end
34
+ ```
35
+
36
+ All the options above can be overridden manually:
37
+
38
+ ```ruby
39
+ Billplz.configuration.api_key = 'your-api-key'
40
+ ```
41
+
42
+ Or, as a hash:
43
+
44
+ ```ruby
45
+ Billplz.configuration = { api_key: 'your-api-key' }
46
+ ```
47
+
48
+ **Collection**
49
+
50
+ Create a new collection:
51
+
52
+ ```ruby
53
+ collection = Billplz::Collection.new({ title: 'My awesome collection' })
54
+ collection.create
55
+ ```
56
+
57
+ **Bill**
58
+
59
+ Create a new bill:
60
+
61
+ ```ruby
62
+ bill = Billplz::Bill.new({ collection_id: VALID_COLLECTION_ID, ... })
63
+ bill.create
64
+ ```
65
+
66
+ Get a bill:
67
+
68
+ ```ruby
69
+ bill = Billplz::Bill.new({ bill_id: 'abc123'})
70
+ bill.get
71
+ ```
72
+
73
+ Delete a bill:
74
+
75
+ ```ruby
76
+ bill = Billplz::Bill.new({ bill_id: 'abc123'})
77
+ bill.delete
78
+ ```
79
+
80
+ **Response**
81
+
82
+ Standard Net::HTTP response will be returned by all of the above methods. However, the gem packed a few helper methods to make your life easier:
83
+
84
+ 1. `#success?`
85
+
86
+ You can check for a successfull request using `success?`, example:
87
+
88
+ ```
89
+ bill.success?
90
+ ```
91
+
92
+ 2. `#parsed_json`
93
+
94
+ This is a convenient helper to parse the JSON response from the API, example:
95
+
96
+ ```ruby
97
+ bill_id = bill.parsed_json['id']
98
+ ```
99
+
100
+ ## Development
101
+
102
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
103
+
104
+ Running `rake test:remote` will run tests that performs actual communication with the API server. Proceed with caution.
105
+
106
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
107
+
108
+ ## Contributing
109
+
110
+ Bug reports and pull requests are welcome on GitHub at https://github.com/syamilmj/billplz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
111
+
112
+ ## License
113
+
114
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ desc "Run the unit test suite"
5
+ task :default => 'test:unit'
6
+ task :test => 'test:unit'
7
+
8
+ namespace :test do
9
+ Rake::TestTask.new(:unit) do |t|
10
+ t.pattern = 'test/unit/**/*_test.rb'
11
+ t.ruby_opts << '-rubygems -w'
12
+ t.libs << 'test'
13
+ t.verbose = true
14
+ end
15
+
16
+ Rake::TestTask.new(:remote) do |t|
17
+ t.pattern = 'test/remote/**/*_test.rb'
18
+ t.ruby_opts << '-rubygems -w'
19
+ t.libs << 'test'
20
+ t.verbose = true
21
+ end
22
+ end
23
+
24
+ desc "Tag and release"
25
+ task :tag_release do
26
+ system "git tag 'v#{Billplz::VERSION}'"
27
+ system "git push --tags"
28
+ end
data/billplz.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'billplz/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "billplz"
8
+ spec.version = Billplz::VERSION
9
+
10
+ spec.summary = 'Abstraction library to interface with the Billplz API'
11
+ spec.homepage = 'http://tideee.com'
12
+ spec.license = 'MIT'
13
+
14
+ spec.author = 'Syamil MJ'
15
+ spec.email = 'syamilmj@tideee.com'
16
+ spec.homepage = 'http://tideee.com/'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "test-unit"
25
+ spec.add_development_dependency "mocha"
26
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "billplz"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/circleci.yml ADDED
@@ -0,0 +1,7 @@
1
+ ruby:
2
+ version:
3
+ 2.3.0
4
+ environment:
5
+ CIRCLE_ENV: test
6
+ dependencies:
7
+ pre: gem install bundler -v 1.11.2
@@ -0,0 +1,22 @@
1
+ module Billplz
2
+ class Bill < Model
3
+ self.api_url = 'https://www.billplz.com/api/v2/bills'
4
+
5
+ def create
6
+ requires!(@payload, :collection_id, :email, :name, :amount, :callback_url)
7
+ request(:post, @payload)
8
+ end
9
+
10
+ def get
11
+ requires!(@payload, :bill_id)
12
+ @api_url = "#{@api_url}/#{@payload[:bill_id]}"
13
+ request(:get, nil)
14
+ end
15
+
16
+ def delete
17
+ requires!(@payload, :bill_id)
18
+ @api_url = "#{@api_url}/#{@payload[:bill_id]}"
19
+ request(:delete, nil)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ module Billplz
2
+ class Collection < Model
3
+ self.api_url = 'https://www.billplz.com/api/v2/collections'
4
+
5
+ def create
6
+ requires!(@payload, :title)
7
+ request(:post, @payload)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,39 @@
1
+ module Billplz
2
+ class Configuration
3
+ attr_accessor :api_key, :http_timeout, :mode
4
+
5
+ def initialize(options={})
6
+ @http_timeout = 30
7
+ @mode = 'live'
8
+ end
9
+
10
+ def options
11
+ hash = Hash.new
12
+ %w[api_key http_timeout mode].map{|key| hash[key.to_sym] = send(key) }
13
+ hash
14
+ end
15
+ end
16
+
17
+ def self.configuration
18
+ @configuration ||= Configuration.new
19
+ end
20
+
21
+ def self.configuration=(args)
22
+ @configuration ||= Configuration.new
23
+ args.each do |arg|
24
+ @configuration.send("#{arg.first}=", arg.last)
25
+ end
26
+ end
27
+
28
+ def self.options
29
+ @configuration.options
30
+ end
31
+
32
+ def self.configure
33
+ yield configuration
34
+ end
35
+
36
+ def self.reset
37
+ @configuration = nil
38
+ end
39
+ end
@@ -0,0 +1,81 @@
1
+ module Billplz
2
+ class Model
3
+ attr_writer :endpoint
4
+ attr_accessor :payload
5
+ attr_accessor :response
6
+
7
+ def initialize(payload={})
8
+ @api_url = self.api_url
9
+ @payload = payload
10
+ end
11
+
12
+ def request(method, body)
13
+ headers = {
14
+ "Authorization" => "Basic " + Base64.encode64(Billplz.configuration.api_key + ":").strip,
15
+ "Content-Type" => "application/json",
16
+ "Accept" => "application/json"
17
+ }
18
+
19
+ @response = case method
20
+ when :get
21
+ raise ArgumentError, "GET requests do not support a request body" if body
22
+ http.get(endpoint.request_uri, headers)
23
+ when :post
24
+ http.post(endpoint.request_uri, body.to_json, headers)
25
+ when :put
26
+ http.put(endpoint.request_uri, body.to_json, headers)
27
+ when :patch
28
+ http.patch(endpoint.request_uri, body, headers)
29
+ when :delete
30
+ raise ArgumentError, "DELETE requests do not support a request body" if body
31
+ http.delete(endpoint.request_uri, headers)
32
+ else
33
+ raise ArgumentError, "Unsupported request method #{method.to_s.upcase}"
34
+ end
35
+
36
+ @response
37
+ end
38
+
39
+ class << self
40
+ attr_accessor :api_url
41
+ end
42
+
43
+ def api_url
44
+ self.class.api_url
45
+ end
46
+
47
+ def endpoint
48
+ URI.parse(@api_url)
49
+ end
50
+
51
+ def success?
52
+ @response.is_a?(Net::HTTPOK)
53
+ end
54
+
55
+ def parsed_json
56
+ JSON.parse(@response.body)
57
+ end
58
+
59
+ private
60
+
61
+ def http
62
+ http = Net::HTTP.new(endpoint.host, endpoint.port)
63
+ http.use_ssl = true
64
+ # http.set_debug_output($stdout)
65
+ http
66
+ end
67
+
68
+ def requires!(hash, *params)
69
+ params.each do |param|
70
+ if param.is_a?(Array)
71
+ raise ArgumentError.new("Missing required parameter: #{param.first}") unless hash.has_key?(param.first)
72
+
73
+ valid_options = param[1..-1]
74
+ raise ArgumentError.new("Parameter: #{param.first} must be one of #{valid_options.to_sentence(:words_connector => 'or')}") unless valid_options.include?(hash[param.first])
75
+ else
76
+ raise ArgumentError.new("Missing required parameter: #{param}") unless hash.has_key?(param)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module Billplz
2
+ VERSION = "0.1.0"
3
+ end
data/lib/billplz.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'base64'
5
+
6
+ require "billplz/version"
7
+ require "billplz/configuration"
8
+ require "billplz/model"
9
+ require "billplz/bill"
10
+ require "billplz/collection"
11
+
12
+ module Billplz
13
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: billplz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Syamil MJ
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email: syamilmj@tideee.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - CODE_OF_CONDUCT.md
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - billplz.gemspec
68
+ - bin/console
69
+ - bin/setup
70
+ - circleci.yml
71
+ - lib/billplz.rb
72
+ - lib/billplz/bill.rb
73
+ - lib/billplz/collection.rb
74
+ - lib/billplz/configuration.rb
75
+ - lib/billplz/model.rb
76
+ - lib/billplz/version.rb
77
+ homepage: http://tideee.com/
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.5.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Abstraction library to interface with the Billplz API
101
+ test_files: []