Skip to content

Commit 87f0b9f

Browse files
author
Will Myers
committed
Initial build
1 parent e1cae67 commit 87f0b9f

File tree

20 files changed

+596
-51
lines changed

20 files changed

+596
-51
lines changed

.gitignore

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,2 @@
1+
Gemfile.lock
12
*.gem
2-
*.rbc
3-
/.config
4-
/coverage/
5-
/InstalledFiles
6-
/pkg/
7-
/spec/reports/
8-
/spec/examples.txt
9-
/test/tmp/
10-
/test/version_tmp/
11-
/tmp/
12-
13-
# Used by dotenv library to load environment variables.
14-
# .env
15-
16-
## Specific to RubyMotion:
17-
.dat*
18-
.repl_history
19-
build/
20-
*.bridgesupport
21-
build-iPhoneOS/
22-
build-iPhoneSimulator/
23-
24-
## Specific to RubyMotion (use of CocoaPods):
25-
#
26-
# We recommend against adding the Pods directory to your .gitignore. However
27-
# you should judge for yourself, the pros and cons are mentioned at:
28-
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29-
#
30-
# vendor/Pods/
31-
32-
## Documentation cache and generated files:
33-
/.yardoc/
34-
/_yardoc/
35-
/doc/
36-
/rdoc/
37-
38-
## Environment normalization:
39-
/.bundle/
40-
/vendor/bundle
41-
/lib/bundler/man/
42-
43-
# for a library or gem, you might want to ignore these files since the code is
44-
# intended to run in multiple environments; otherwise, check them in:
45-
# Gemfile.lock
46-
# .ruby-version
47-
# .ruby-gemset
48-
49-
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50-
.rvmrc

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: ruby
2+
3+
rvm:
4+
- 1.9.3
5+
- 2.0.0
6+
- 2.1
7+
- 2.2
8+
- 2.3.0

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1.0.0 August 11, 2016
2+
- Initial Release

Gemfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec
4+
5+
group :development do
6+
gem 'rake'
7+
gem 'test-unit'
8+
gem 'webmock'
9+
end

README.md

Lines changed: 125 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,125 @@
1-
# button-client-ruby
2-
ruby client for the Button Order API
1+
# button-client-ruby [![Build Status](https://travis-ci.org/button/button-client-ruby.svg?branch=master)](https://travis-ci.org/button/button-client-ruby)
2+
3+
This module is a thin client for interacting with Button's API.
4+
5+
Please see the full [API Docs](https://www.usebutton.com/developers/api-reference) for more information.
6+
7+
#### Supported runtimes
8+
9+
* Ruby (MRI) `>=1.9.3`
10+
11+
#### Dependencies
12+
13+
* None
14+
15+
## Usage
16+
17+
```bash
18+
gem install button
19+
```
20+
21+
To create a client capable of making network requests, instantiate a `Button::Client` with your [API key](https://app.usebutton.com/settings/organization).
22+
23+
```ruby
24+
require 'button'
25+
26+
client = Button::Client.new('sk-XXX')
27+
```
28+
29+
The client will always attempt to raise a `Button::ButtonClientError` in an error condition.
30+
31+
All API requests will return a `Button::Response` instance, which supports accessing data properties from the API response as methods. To access the raw response hash, use `#to_hash`. For instance:
32+
33+
```ruby
34+
require 'button'
35+
36+
client = Button::Client.new('sk-XXX')
37+
38+
begin
39+
response = client.orders.get('btnorder-XXX')
40+
rescue Button::ButtonClientError => error
41+
puts error
42+
end
43+
44+
puts response
45+
# => Button::Response(button_order_id: btnorder-XXX, total: 60, ... )
46+
47+
puts response.button_order_id
48+
# => btnorder-XXX
49+
50+
puts response.to_hash()
51+
# => {:button_order_id=>'btnorder-29de0b1436075ea6', :total=>60, ... }
52+
```
53+
54+
n.b. the keys of the response hash will always be symbols.
55+
56+
## Resources
57+
58+
We currently expose only one resource to manage, `Orders`.
59+
60+
### Orders
61+
62+
**n.b: all currency values should be reported in the smallest possible unit of that denomination, i.e. $1.00 should be reported as `100` (i.e. 100 pennies)**
63+
64+
##### Create
65+
66+
```ruby
67+
require 'button'
68+
69+
client = Button::Client.new('sk-XXX')
70+
71+
response = client.orders.create({
72+
total: 50,
73+
currency: 'USD',
74+
order_id: '1994',
75+
finalization_date: '2017-08-02T19:26:08Z'
76+
})
77+
78+
puts response
79+
# => Button::Response(button_order_id: btnorder-XXX, total: 50, ... )
80+
```
81+
82+
##### Get
83+
84+
```ruby
85+
require 'button'
86+
87+
client = Button::Client.new('sk-XXX')
88+
89+
response = client.orders.get('btnorder-XXX')
90+
91+
puts response
92+
# => Button::Response(button_order_id: btnorder-XXX, total: 50, ... )
93+
```
94+
##### Update
95+
96+
```ruby
97+
require 'button'
98+
99+
client = Button::Client.new('sk-XXX')
100+
101+
response = client.orders.update('btnorder-XXX', total: 60)
102+
103+
puts response
104+
# => Button::Response(button_order_id: btnorder-XXX, total: 60, ... )
105+
```
106+
107+
##### Delete
108+
109+
```ruby
110+
require 'button'
111+
112+
client = Button::Client.new('sk-XXX')
113+
114+
response = client.orders.delete('btnorder-XXX')
115+
116+
puts response
117+
# => Button::Response()
118+
```
119+
120+
## Contributing
121+
122+
* Building the gem: `gem build button.gemspec`
123+
* Installing locally: `gem install ./button-X.Y.Z.gem`
124+
* Installing development dependencies: `bundle install`
125+
* Running tests: `bundle exec rake`

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'rake/testtask'
2+
3+
task :default => [:test]
4+
5+
Rake::TestTask.new do |t|
6+
t.pattern = './test/**/*_test.rb'
7+
end

bin/console

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env ruby
2+
3+
require "irb"
4+
require "#{File.expand_path('../../lib', __FILE__)}/button.rb"
5+
6+
IRB.start

button.gemspec

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
lib = File.expand_path('../lib', __FILE__)
2+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3+
4+
require 'button'
5+
6+
Gem::Specification.new do |spec|
7+
spec.name = 'button'
8+
spec.version = Button::VERSION
9+
spec.authors = ['Button']
10+
spec.email = ['support@usebutton.com']
11+
spec.summary = 'ruby client for the Button Order API'
12+
spec.description = 'Button is a contextual acquisition channel and closed-loop attribution and affiliation system for mobile commerce.'
13+
spec.homepage = 'https://usebutton.com'
14+
15+
spec.files = Dir.glob('lib/**/*') + ['LICENSE', 'README.md', 'CHANGELOG.md']
16+
spec.license = 'MIT'
17+
spec.require_paths = ['lib']
18+
spec.required_ruby_version = '>= 1.9.3'
19+
end

lib/button.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require 'button/client'
2+
require 'button/version'

lib/button/client.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'button/resources/orders'
2+
require 'button/errors'
3+
4+
module Button
5+
# Client is the top-level interface for the Button API. It exposes one
6+
# resource currently: `.orders`. It requires a valid API key to make
7+
# requests on behalf of your organization, which can be found at
8+
# https://app.usebutton.com/settings/organization.
9+
#
10+
# ## Usage
11+
#
12+
# client = Button::Client.new("sk-XXX")
13+
# puts client.orders.get("btnorder-XXX")
14+
#
15+
class Client
16+
def initialize(api_key)
17+
if api_key.nil? || api_key.empty?
18+
raise ButtonClientError, 'Must provide a Button API key. Find yours at https://app.usebutton.com/settings/organization'
19+
end
20+
21+
@orders = Orders.new(api_key)
22+
end
23+
24+
attr_reader :orders
25+
end
26+
end

0 commit comments

Comments
 (0)