analogbridge 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.
@@ -0,0 +1,3 @@
1
+ AnalogBridge.configure do |config|
2
+ config.secret_key = "YOUR_SECRET_KEY"
3
+ end
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in analogbridge.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Analog Bridge
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,227 @@
1
+ # Analog Bridge
2
+
3
+ [![Build
4
+ Status](https://travis-ci.org/analogbridge/analog-bridge-ruby.svg?branch=master)](https://travis-ci.org/analogbridge/analog-bridge-ruby)
5
+ [![Code
6
+ Climate](https://codeclimate.com/github/analogbridge/analog-bridge-ruby/badges/gpa.svg)](https://codeclimate.com/github/analogbridge/analog-bridge-ruby)
7
+
8
+ Analog Bridge is comprised of a JavaScript client and REST API which enables
9
+ your users to import analog media directly into your app or website.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem "analogbridge", github: "analogbridge/analog-bridge-ruby"
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```sh
22
+ $ bundle install
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```sh
28
+ $ gem install analogbridge
29
+ ```
30
+
31
+ ## Configure
32
+
33
+ Once you have your API Keys from Analog Bridge, you can initialize your configuration with your `secret_key` as
34
+
35
+ ```ruby
36
+ AnalogBridge.configure do |config|
37
+ config.secret_key = "YOUR_SECRET_KEY"
38
+ end
39
+ ```
40
+
41
+ Or
42
+
43
+ ```ruby
44
+ AnalogBridge.configuration.secret_key = "YOUR_SECRET_KEY"
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ ### Customer
50
+
51
+ #### Create Customer
52
+
53
+ To create a new customer using the API, usage
54
+
55
+ ```ruby
56
+ AnalogBridge::Customer.create(
57
+ email: "demo@analogbridge.io",
58
+ shipping: {
59
+ first_name: "John",
60
+ last_name: "Smith",
61
+ address1: "3336 Commercial Ave",
62
+ city: "Northbrook",
63
+ state: "IL",
64
+ zip: "60062",
65
+ phone: "800-557-3508",
66
+ email: "demo@analogbridge.io"
67
+ },
68
+ metadata: {
69
+ user_id: "123456",
70
+ }
71
+ )
72
+ ```
73
+
74
+ #### Retrieve a Customer
75
+
76
+ We can easily retrieve a customer's details using their `customer_id`, for
77
+ example to find a customer with details with id `cus_12345678`
78
+
79
+ ```ruby
80
+ AnalogBridge::Customer.find("cus_12345678")
81
+ ```
82
+
83
+ #### Retrieve all customers
84
+
85
+ Analog Bridge provides an interface to retrieve all your customers very easily.
86
+ To retrieve all of your customers, you can use
87
+
88
+ ```ruby
89
+ AnalogBridge::Customer.list(limit: 20, offset: 100)
90
+ ```
91
+
92
+ #### Update a customer
93
+
94
+ Update an existing customer's information by using the `cus_id` from customer
95
+ creation. Any unprovided parameters will have no effect on the customer object.
96
+ The arguments for this call are mainly the same as for the customer creation
97
+ call.
98
+
99
+ ```ruby
100
+ AnalogBridge::Customer.update(
101
+ "cus_123456789",
102
+ email: "newemail@analogbridge.io"
103
+ )
104
+ ```
105
+
106
+ #### Delete a customer
107
+
108
+ If we need to delete a customer, for example id `cus_123456789`, then we can
109
+ use
110
+
111
+ ```ruby
112
+ AnalogBridge::Customer.delete("cus_123456789")
113
+ ```
114
+
115
+ ### Order
116
+
117
+ #### List all orders
118
+
119
+ The Analog Bridge API allow us to retrieve all orders by a specific `customer`.
120
+ For example we want to retrieve all `orders` by customer id `cus_12345678`,
121
+ we can use
122
+
123
+ ```ruby
124
+ AnalogBridge::Order.where(customer_id: "cus_12345678")
125
+ ```
126
+
127
+ #### List order details
128
+
129
+ If we need to retrieve the details for a specific order then we can use
130
+
131
+ ```ruby
132
+ AnalogBridge::Order.where(
133
+ order_id: "order_12345678",
134
+ customer_id: "cus_12345678"
135
+ )
136
+ ```
137
+
138
+ #### Retrieve import ready orders
139
+ Once customer orders have been processed and uploaded to our Cloud, they are import-ready for your system.
140
+ To retrieve the list of import ready orders, we can use
141
+
142
+ ```ruby
143
+ AnalogBridge::Order.import_ready
144
+ ```
145
+
146
+ ### Product
147
+
148
+ #### Listing products
149
+
150
+ To retrieve the `products` simply use the following interface
151
+
152
+ ```ruby
153
+ AnalogBridge::Product.list
154
+ ```
155
+
156
+ ## Development
157
+
158
+ We are following Sandi Metz's Rules for this gem, you can read the
159
+ [description of the rules here]
160
+ (http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers). All new code should follow these rules. If you make changes in a pre-existing
161
+ file that violates these rules you should fix the violations as part of
162
+ your contribution.
163
+
164
+ ### Setup
165
+
166
+ Clone the repository.
167
+
168
+ ```sh
169
+ git clone https://github.com/analogbridge/analog-bridge-ruby
170
+ ```
171
+
172
+ Setup your environment.
173
+
174
+ ```sh
175
+ bin/setup
176
+ ```
177
+
178
+ Run the test suite
179
+
180
+ ```sh
181
+ bin/rspec
182
+ ```
183
+
184
+ ### PlayBox
185
+
186
+ Setup API keys.
187
+
188
+ ```sh
189
+ cp .sample.pryrc .pryrc
190
+ vim .pryrc
191
+ ```
192
+
193
+ Start your console.
194
+
195
+ ```sh
196
+ bin/console
197
+ ```
198
+
199
+ Start playing with it.
200
+
201
+ ```ruby
202
+ AnalogBridge::Customer.list
203
+ ```
204
+
205
+ ## Contributing
206
+
207
+ First, thank you for contributing! We love pull requests from everyone. By
208
+ participating in this project, you hereby grant the right to grant or transfer
209
+ an unlimited number of non exclusive licenses or sub-licenses to third parties,
210
+ under the copyright covering the contribution to use the contribution by all
211
+ means.
212
+
213
+ Here are a few technical guidelines to follow:
214
+
215
+ 1. Open an [issue][issues] to discuss a new feature.
216
+ 1. Write tests to support your new feature.
217
+ 1. Make sure the entire test suite passes locally and on CI.
218
+ 1. Open a Pull Request.
219
+ 1. [Squash your commits][squash] after receiving feedback.
220
+ 1. Party!
221
+
222
+ [issues]: https://github.com/analogbridge/analog-bridge-ruby/issues
223
+ [squash]: https://github.com/thoughtbot/guides/tree/master/protocol/git#write-a-feature
224
+
225
+ ## License
226
+
227
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "analogbridge/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "analogbridge"
8
+ spec.version = AnalogBridge::VERSION
9
+ spec.authors = ["Eugene Gekhter", "Abu Nashir"]
10
+ spec.email = ["eg@gomemorable.com", "abunashir@gmail.com"]
11
+
12
+ spec.summary = %q{Import any analog media format into your cloud app}
13
+ spec.description = %q{Enable users to import any analog media format directly into your app with the Analog Bridge API}
14
+ spec.homepage = "https://analogbridge.io"
15
+ spec.license = "MIT"
16
+
17
+ spec.require_paths = ["lib"]
18
+ spec.files = `git ls-files`.split("\n")
19
+ spec.test_files = `git ls-files -- {spec}/*`.split("\n")
20
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.1.9")
21
+
22
+ spec.add_dependency "rest-client", "~> 2.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "webmock", "~> 2.0"
28
+ spec.add_development_dependency "pry", "~> 0.10.3"
29
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "analogbridge"
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
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rspec' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rspec-core", "rspec")
@@ -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,9 @@
1
+ require "analogbridge/version"
2
+ require "analogbridge/client"
3
+ require "analogbridge/base"
4
+ require "analogbridge/order"
5
+ require "analogbridge/product"
6
+ require "analogbridge/customer"
7
+
8
+ module AnalogBridge
9
+ end
@@ -0,0 +1,11 @@
1
+ module AnalogBridge
2
+ class Base
3
+ def self.method_missing(method_name, *arguments, &block)
4
+ if new.respond_to?(method_name, include_private: false)
5
+ new.send(method_name, *arguments, &block)
6
+ else
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,46 @@
1
+ require "rest-client"
2
+ require "analogbridge/configuration"
3
+ require "analogbridge/response"
4
+
5
+ module AnalogBridge
6
+ class Client
7
+ attr_reader :http_method, :end_point, :attributes
8
+
9
+ def initialize(http_method, end_point, attributes = {})
10
+ @end_point = end_point
11
+ @http_method = http_method
12
+ @attributes = attributes
13
+ end
14
+
15
+ def execute
16
+ Response.new(execute_api_request).parse
17
+ end
18
+
19
+ private
20
+
21
+ def execute_api_request
22
+ RestClient::Request.execute(
23
+ method: http_method,
24
+ url: api_end_point,
25
+ payload: attributes,
26
+ user: AnalogBridge.configuration.secret_key,
27
+ )
28
+ end
29
+
30
+ def api_end_point
31
+ [AnalogBridge.configuration.api_host, end_point].join("/")
32
+ end
33
+ end
34
+
35
+ def self.get_resource(end_point)
36
+ Client.new(:get, end_point).execute
37
+ end
38
+
39
+ def self.post_resource(end_point, attributes)
40
+ Client.new(:post, end_point, attributes).execute
41
+ end
42
+
43
+ def self.delete_resource(end_point)
44
+ Client.new(:delete, end_point).execute
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ module AnalogBridge
2
+ class Configuration
3
+ attr_accessor :api_base, :api_version, :secret_key
4
+
5
+ def initialize
6
+ @api_base ||= "https://api.analogbridge.io"
7
+ @api_version ||= "v1"
8
+ end
9
+
10
+ def api_host
11
+ [api_base, api_version].join("/")
12
+ end
13
+ end
14
+
15
+ def self.configure
16
+ yield configuration
17
+ end
18
+
19
+ def self.configuration
20
+ @configuration ||= Configuration.new
21
+ end
22
+ end
@@ -0,0 +1,31 @@
1
+ module AnalogBridge
2
+ class Customer < AnalogBridge::Base
3
+ def find(customer_id)
4
+ AnalogBridge.get_resource(
5
+ ["customers", customer_id].join("/"),
6
+ )
7
+ end
8
+
9
+ def list(limit: 20, offset: 0)
10
+ AnalogBridge.get_resource(
11
+ "customers?limit=#{limit}&offset=#{offset}",
12
+ )
13
+ end
14
+
15
+ def create(attributes = {})
16
+ AnalogBridge.post_resource("customers", attributes).data
17
+ end
18
+
19
+ def update(customer_id, attributes = {})
20
+ AnalogBridge.post_resource(
21
+ ["customers", customer_id].join("/"), attributes
22
+ ).data
23
+ end
24
+
25
+ def delete(customer_id)
26
+ AnalogBridge.delete_resource(
27
+ ["customers", customer_id].join("/"),
28
+ ).data
29
+ end
30
+ end
31
+ end