bond-ruby 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: d31946ed0265ccc303970380a829c660a6113e72
4
+ data.tar.gz: 87eb57a8cf864f291bb2c8ae2fc404714806f6c9
5
+ SHA512:
6
+ metadata.gz: fbe73fcd46373bab3a34f45da6518735a2c489ee598eecd3173000384e4fcc2386efb4a601380293117ec11f43c25a3aee5a06ab5d0511598a29813e088c3bfa
7
+ data.tar.gz: 2a48f04e67c4392077a1c10b34b46fe30798e09134ad057c9796c7bec5f2a3d603d0ea3e44a2b916377211c90e0473b038eebd74d1599529f98d9143cf0349dd
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bond.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 John Gerhardt
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,52 @@
1
+ # Bond
2
+ [![Circle CI](https://circleci.com/gh/jwg2s/bond-ruby/tree/develop.svg?style=shield)](https://circleci.com/gh/jwg2s/bond-ruby/tree/develop)
3
+ [![Code Climate](https://codeclimate.com/github/jwg2s/bond-ruby/badges/gpa.svg)](https://codeclimate.com/github/jwg2s/bond-ruby)
4
+ [![Test Coverage](https://codeclimate.com/github/jwg2s/bond-ruby/badges/coverage.svg)](https://codeclimate.com/github/jwg2s/bond-ruby/coverage)
5
+
6
+ Full documentation of the Bond API can be found here: http://docs.bond.apiary.io.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'bond-ruby'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```
19
+ bundle
20
+ ```
21
+
22
+ Or install it yourself with:
23
+
24
+ ```
25
+ gem install bond-ruby
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ### Set your API Key
31
+
32
+ ```
33
+ Bond.api_key = 'XXX'
34
+ ```
35
+
36
+ ### Fetch your Account
37
+
38
+ ```
39
+ Bond::Account.new
40
+ ```
41
+
42
+ ### More usages
43
+ Please view the specs to find examples of how the various classes can be used together.
44
+
45
+ ## Contributing
46
+
47
+ If you would like to contribute, please ensure any new functionality or modified existing functionality is well tested with automated tests. Open a pull request to this repository and I will review it and make sure it is either accepted or rejected within a reasonable time.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
52
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/*_test.rb']
7
+ t.verbose = true
8
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'bond'
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/bond.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bond/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'bond-ruby'
8
+ spec.version = Bond::VERSION
9
+ spec.authors = ['John Gerhardt']
10
+ spec.email = ['jgerhardt@contactually.com']
11
+
12
+ spec.summary = %q{Bond API Ruby Wrapper}
13
+ spec.description = %q{This gem helps wrap Bond's API in a easy-to-use ruby gem.}
14
+ spec.homepage = 'https://hellobond.com'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'minitest'
31
+ spec.add_development_dependency 'codeclimate-test-reporter'
32
+ spec.add_development_dependency 'vcr'
33
+ spec.add_development_dependency 'webmock'
34
+ spec.add_development_dependency 'byebug'
35
+
36
+ spec.add_development_dependency 'bundler'
37
+ spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'faraday'
39
+ spec.add_development_dependency 'json'
40
+ end
data/lib/bond.rb ADDED
@@ -0,0 +1,24 @@
1
+ require_relative 'bond/version'
2
+ require_relative 'bond/connection'
3
+ require_relative 'bond/errors'
4
+ require_relative 'bond/account'
5
+ require_relative 'bond/order'
6
+ require_relative 'bond/message'
7
+ require_relative 'bond/preview'
8
+ require_relative 'bond/preview/message_preview'
9
+ require_relative 'bond/preview/envelope_preview'
10
+
11
+
12
+ module Bond
13
+ API_URL = 'https://api.hellobond.com'
14
+
15
+ # @param [String] key
16
+ def self.api_key=(key)
17
+ @api_key = key
18
+ end
19
+
20
+ # @return [String]
21
+ def self.api_key
22
+ @api_key
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Bond
5
+ class Account
6
+ attr_accessor :first_name, :last_name, :email, :credits, :links
7
+
8
+ def initialize
9
+ response = Bond::Connection.connection.get('/account')
10
+ json = JSON.parse(response.body)
11
+
12
+ Bond::BondError.handle_errors(json)
13
+
14
+ json['data'].each { |name, value| instance_variable_set("@#{name}", value) }
15
+ @links = json['links']
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ require 'faraday'
2
+
3
+ module Bond
4
+ class Connection
5
+ attr_accessor :connection
6
+
7
+ class << self
8
+ # Create instances of connection object to ensure thread safety
9
+ # @return [Faraday] connection
10
+ def connection
11
+ new.connection
12
+ end
13
+ end
14
+
15
+ def initialize
16
+ connection = Faraday.new(url: Bond::API_URL)
17
+ connection.basic_auth(Bond.api_key, nil)
18
+ @connection = connection
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Bond
2
+ class BondError < StandardError
3
+ attr_reader :http_code, :application_error_code
4
+
5
+ class << self
6
+ # @param [Hash] json
7
+ def handle_errors(json)
8
+ errors = json['errors']
9
+ if errors
10
+ error_message = errors.map { |error| "Code: #{error['code']}. Message: #{error['message']}" }.join(' ')
11
+ raise Bond::BondError.new(error_message)
12
+ end
13
+ end
14
+ end
15
+
16
+ # @param [String] message
17
+ def initialize(message)
18
+ super(message)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Bond
5
+ class Message
6
+ attr_accessor :guid, :stationary_id, :handwriting, :content, :recipient_address, :sender_address, :links
7
+
8
+ # @param [Hash] attributes
9
+ def initialize(attributes = {})
10
+ attributes.each { |name, value| instance_variable_set("@#{name}", value) }
11
+ end
12
+ end
13
+ end
data/lib/bond/order.rb ADDED
@@ -0,0 +1,94 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Bond
5
+ class Order
6
+ attr_accessor :guid, :created_at, :status, :products, :shipping, :total, :links
7
+
8
+ class << self
9
+ # @param [Hash] options
10
+ # @return [Array<Bond::Order>]
11
+ def all(options = {})
12
+ page = options[:page]
13
+ response = Bond::Connection.connection.get("/orders?page=#{page || 1}")
14
+
15
+ JSON.parse(response.body)['data'].map do |attributes|
16
+ new(attributes)
17
+ end
18
+ end
19
+
20
+ # @return [Hash]
21
+ def pagination
22
+ @pagination ||= begin
23
+ response = Bond::Connection.connection.get('/orders')
24
+ JSON.parse(response.body)['pagination'] || {}
25
+ end
26
+ end
27
+
28
+ # @param [String] guid
29
+ # @return [Bond::Order]
30
+ def find(guid)
31
+ response = Bond::Connection.connection.get("/orders/#{guid}")
32
+ attributes = JSON.parse(response.body)['data']
33
+ new(attributes)
34
+ end
35
+
36
+ # @return [Bond::Order]
37
+ def create
38
+ response = Bond::Connection.connection.post('/orders')
39
+ json = JSON.parse(response.body)
40
+
41
+ Bond::BondError.handle_errors(json)
42
+
43
+ attributes = json['data']
44
+ new(attributes)
45
+ end
46
+ end
47
+
48
+ # @param [Hash] attributes
49
+ def initialize(attributes = {})
50
+ attributes.each { |name, value| instance_variable_set("@#{name}", value) }
51
+ end
52
+
53
+ # @return [Boolean]
54
+ def process
55
+ response = Bond::Connection.connection.post("/orders/#{guid}/process")
56
+ json = JSON.parse(response.body)
57
+
58
+ Bond::BondError.handle_errors(json)
59
+
60
+ attributes = json['data']
61
+ attributes.each { |name, value| instance_variable_set("@#{name}", value) }
62
+ self.links = json['links']
63
+ response.success?
64
+ end
65
+
66
+ # @param [Hash] message_hash
67
+ # @return [Boolean]
68
+ def add_message(message_hash)
69
+ response = Bond::Connection.connection.post("/orders/#{guid}/messages", message_hash)
70
+
71
+ @messages = nil
72
+ response.success?
73
+ end
74
+
75
+ # @return [Array<Bond::Message>]
76
+ def messages
77
+ @messages ||= begin
78
+ response = Bond::Connection.connection.get("/orders/#{guid}/messages")
79
+ messages = JSON.parse(response.body)['data']
80
+ messages.map do |attributes|
81
+ Message.new(attributes)
82
+ end
83
+ end
84
+ end
85
+
86
+ # @return [Hash]
87
+ def message_pagination
88
+ @message_pagination ||= begin
89
+ response = Bond::Connection.connection.get("/orders/#{guid}/messages")
90
+ JSON.parse(response.body)['pagination'] || {}
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,18 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Bond
5
+ class Preview
6
+ attr_accessor :request_params
7
+
8
+ # @param [Hash] attributes
9
+ def initialize(attributes = {})
10
+ @request_params = attributes
11
+ end
12
+
13
+ # @return [Hash] attributes
14
+ def request_preview
15
+ raise 'Subclass must implement this method'
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Bond
5
+ class EnvelopePreview < Preview
6
+ attr_accessor :encoded_envelope, :encoded_envelope_hash, :encoded_envelope_timestamp, :img
7
+
8
+ # @return [Hash] attributes
9
+ def request_preview
10
+ response = Bond::Connection.connection.post('/messages/preview/envelope', request_params)
11
+ json = JSON.parse(response.body)
12
+
13
+ Bond::BondError.handle_errors(json)
14
+
15
+ attributes = json['data']
16
+ attributes.each { |name, value| instance_variable_set("@#{name}", value) }
17
+ attributes
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Bond
5
+ class MessagePreview < Preview
6
+ attr_accessor :encoded_content, :encoded_content_hash, :encoded_content_timestamp, :img
7
+
8
+ # @return [Hash] attributes
9
+ def request_preview
10
+ response = Bond::Connection.connection.post('/messages/preview/content', request_params)
11
+ json = JSON.parse(response.body)
12
+
13
+ Bond::BondError.handle_errors(json)
14
+
15
+ attributes = json['data']
16
+ attributes.each { |name, value| instance_variable_set("@#{name}", value) }
17
+ attributes
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Bond
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bond-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - John Gerhardt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
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: codeclimate-test-reporter
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: vcr
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
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
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
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: json
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: This gem helps wrap Bond's API in a easy-to-use ruby gem.
140
+ email:
141
+ - jgerhardt@contactually.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".ruby-version"
148
+ - Gemfile
149
+ - LICENSE.txt
150
+ - README.md
151
+ - Rakefile
152
+ - bin/console
153
+ - bin/setup
154
+ - bond.gemspec
155
+ - lib/bond.rb
156
+ - lib/bond/account.rb
157
+ - lib/bond/connection.rb
158
+ - lib/bond/errors.rb
159
+ - lib/bond/message.rb
160
+ - lib/bond/order.rb
161
+ - lib/bond/preview.rb
162
+ - lib/bond/preview/envelope_preview.rb
163
+ - lib/bond/preview/message_preview.rb
164
+ - lib/bond/version.rb
165
+ homepage: https://hellobond.com
166
+ licenses:
167
+ - MIT
168
+ metadata:
169
+ allowed_push_host: https://rubygems.org
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 2.4.8
187
+ signing_key:
188
+ specification_version: 4
189
+ summary: Bond API Ruby Wrapper
190
+ test_files: []