cardonline 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d41c3777037dd897070501307cd301c1e7515165
4
+ data.tar.gz: bb31893d9e2187b940f7bef598961eaae0f7424e
5
+ SHA512:
6
+ metadata.gz: b70d7292c5f0d75fb96b0bc0a7a1f6dee7ac4b5527237c6768345143f1b219f055a35b03578b0590d86b67cf7112fa3a8b87abe58cf2ff792823ab4588fa3a02
7
+ data.tar.gz: 8b57f5213cf97694aa43f3246d36786cab01f9f463c35cec02e75ebc5701ae1973b896b72ee5ff3131df89a52b74781d98ac7a85e95fa20d86f00da3d29d29e1
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.15.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in cardonline.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Emric
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,112 @@
1
+ # Cardonline
2
+
3
+ This gem is a simple wrapper around the cardonline API. You can find their
4
+ documentation (here)[http://cardonline.se/doc/].
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'cardonline'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install cardonline
21
+
22
+ ## Usage
23
+
24
+ ### Installation
25
+ The only installation needed is adding the username and password to be used in
26
+ the API. The client will perform basic auth to perform the requests.
27
+
28
+ ```ruby
29
+ Cardonline.configure do |config|
30
+ config.username = "username"
31
+ config.password = "password"
32
+ end
33
+ ```
34
+
35
+ This gem follows the `Safettp` pattern for perform requests, which means you
36
+ have to provide a path for both the success state and the failure state. You can
37
+ read more (here)[https://github.com/Istanful/safettp].
38
+ ```ruby
39
+ Cardonline.get_card(1) do |result|
40
+ result.on_success do |response|
41
+ puts response.parsed_body
42
+ end
43
+
44
+ result.on_failure do |response|
45
+ puts response.http_response.code
46
+ end
47
+ end
48
+ ```
49
+
50
+ ### Get a card
51
+ Fetch a card with the provided id.
52
+ ```ruby
53
+ Cardonline.get_card(1) do |result|
54
+ result.on_success do |response|
55
+ end
56
+
57
+ result.on_failure do |response|
58
+ end
59
+ end
60
+ ```
61
+
62
+ Add a card with the provided attributes.
63
+ ```ruby
64
+ Cardonline.add_card({ name: 'Christian' }) do |result|
65
+ result.on_success do |response|
66
+ end
67
+
68
+ result.on_failure do |response|
69
+ end
70
+ end
71
+ ```
72
+
73
+ Update a card with the provided id with the provided attributes.
74
+ ```ruby
75
+ Cardonline.update_card(1, { name: 'James' }) do |result|
76
+ result.on_success do |response|
77
+ end
78
+
79
+ result.on_failure do |response|
80
+ end
81
+ end
82
+ ```
83
+
84
+ Retrieve the performed orders.
85
+ ```ruby
86
+ Cardonline.get_orders do |result|
87
+ result.on_success do |response|
88
+ end
89
+
90
+ result.on_failure do |response|
91
+ end
92
+ end
93
+ ```
94
+
95
+ Retrieve a specific order.
96
+ ```ruby
97
+ Cardonline.get_order(1) do |result|
98
+ result.on_success do |response|
99
+ end
100
+
101
+ result.on_failure do |response|
102
+ end
103
+ end
104
+ ```
105
+
106
+ ## Contributing
107
+
108
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cardonline.
109
+
110
+ ## License
111
+
112
+ 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,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cardonline"
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(__FILE__)
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
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cardonline/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cardonline"
8
+ spec.version = Cardonline::VERSION
9
+ spec.authors = ["Emric"]
10
+ spec.email = ["emric.mansson@gmail.com"]
11
+
12
+ spec.summary = %q{A thin wrapper around the cardonline api}
13
+ spec.description = %q{A thin wrapper around the cardonline api}
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_runtime_dependency 'safettp'
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.15"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency "webmock"
38
+ end
data/lib/cardonline.rb ADDED
@@ -0,0 +1,34 @@
1
+ require "cardonline/version"
2
+ require "forwardable"
3
+ require "safettp"
4
+ require "cardonline/client"
5
+
6
+ module Cardonline
7
+ class << self
8
+ extend Forwardable
9
+
10
+ attr_accessor :config
11
+
12
+ def_delegators :client, :add_card, :get_card, :update_card,
13
+ :get_orders, :get_order
14
+
15
+ def client
16
+ Cardonline::Client
17
+ end
18
+ end
19
+
20
+ class Configuration
21
+ attr_accessor :username, :password, :base_url
22
+
23
+ def initialize
24
+ @base_url = 'https://cardonline.se/api'
25
+ end
26
+ end
27
+
28
+ def self.configure
29
+ @config ||= Configuration.new
30
+ yield(@config)
31
+ Cardonline::Client.configure_from_master(@config)
32
+ end
33
+ end
34
+
@@ -0,0 +1,36 @@
1
+ class Cardonline::Client
2
+ include Safettp::Client
3
+
4
+ def self.configure_from_master(master_config)
5
+ configure do |config|
6
+ config.base_url = master_config.base_url
7
+ config.default_options = {
8
+ auth: {
9
+ type: :basic,
10
+ username: master_config.username,
11
+ password: master_config.password
12
+ }
13
+ }
14
+ end
15
+ end
16
+
17
+ def add_card(template_id, body, &block)
18
+ post('/cards', body: body, query: { template_id: template_id }, &block)
19
+ end
20
+
21
+ def get_card(card_id, &block)
22
+ get("/cards/#{card_id}", &block)
23
+ end
24
+
25
+ def update_card(card_id, attributes, &block)
26
+ put("/cards/#{card_id}", body: attributes, &block)
27
+ end
28
+
29
+ def get_order(order_id, &block)
30
+ get("/orders/#{order_id}", &block)
31
+ end
32
+
33
+ def get_orders(&block)
34
+ get("/orders", &block)
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Cardonline
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cardonline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Emric
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: safettp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A thin wrapper around the cardonline api
84
+ email:
85
+ - emric.mansson@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - cardonline.gemspec
100
+ - lib/cardonline.rb
101
+ - lib/cardonline/client.rb
102
+ - lib/cardonline/version.rb
103
+ homepage:
104
+ licenses:
105
+ - MIT
106
+ metadata:
107
+ allowed_push_host: https://rubygems.org
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.5.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: A thin wrapper around the cardonline api
128
+ test_files: []