doshii 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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eca56ca2714b029d9da78f34ddf852a02bfd3cb9
4
+ data.tar.gz: e7ee47054bf5cd141f402b10fa26ce6a086f03b7
5
+ SHA512:
6
+ metadata.gz: 0714ab4409c9f0d727c5e0c2b3b9b95d96065a105a50c484f98a763a762bd21c1ef321929b482990fa4818443a00b2f6b8ac700b3f4bacd0e26550b0c649924f
7
+ data.tar.gz: aa11be65f5a6fda18e0d5f9c17778bbca5fcb0e79bbc0b7b0700949a7cf5ebbd667fd64e1f8ace906011acc74f472e057096c9aa23bb173929fb8f0b81f07db4
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in doshii.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Romel Campos
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.
@@ -0,0 +1,152 @@
1
+ # Doshii
2
+
3
+ A Doshii API wrapper gem. Refer to [alphasandbox.doshii.co](https://alphasandbox.doshii.co/docs/partner/api/) for Doshii's API official documentation.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'doshii'
12
+ ```
13
+ or
14
+ ```ruby
15
+ gem 'doshii', :git => 'https://github.com/devrc-trise/doshii.git', :branch => 'develop'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install doshii
25
+
26
+ Run this to create configuration file ```config/initializers/doshii.rb```:
27
+
28
+ $ rails g doshii:install
29
+
30
+ Change ```config/initializers/doshii.rb``` as necessary. You might want to set values in system env or environment files to differentiate development, test and production details:
31
+ ```ruby
32
+ Doshii.configure do |config|
33
+ # you might want to set these values in environment files
34
+ config.client_id = '369c27e8d884e0b54e56035b41eed4b07b0fc59091907418f0368ab643a4ad31'
35
+ config.client_secret = 'c0c0441e9bcc671dff9beb8e2a16fb43ed392f8c9a029dc8075cb71b1ac87e5f'
36
+ config.endpoint = 'https://alphasandbox.doshii.co/partner/api'
37
+ config.verify_ssl = false
38
+ config.version = 'v1'
39
+ end
40
+ ```
41
+
42
+ rock'n'roll
43
+
44
+ ## Usage
45
+
46
+ **CHECKINS**
47
+
48
+ DELETE /checkins/:checkinId
49
+ ```ruby
50
+ Doshii.checkin.delete :checkin_id
51
+ ```
52
+ GET /checkins/:checkinId
53
+ ```ruby
54
+ Doshii.checkin.find :checkin_id
55
+ ```
56
+ POST /checkins/:locationId
57
+ ```ruby
58
+ Doshii.checkin.create :location_id do |params|
59
+ params[:name] = 'John Smith'
60
+ params[:externalId] = 'ias2kk2'
61
+ params[:photoURL] = 'http://example.com/profile.png'
62
+ end
63
+ ```
64
+ or
65
+ ```ruby
66
+ checkin_params = {
67
+ name: 'John Smith',
68
+ externalId: 'ias2kk2',
69
+ photoURL: 'http://example.com/profile.png'
70
+ }
71
+ Doshii.checkin.create :location_id do |param|
72
+ params.merge!(checkin_params)
73
+ end
74
+ ```
75
+
76
+ **LOCATIONS**
77
+
78
+ GET /locations
79
+ ```ruby
80
+ Doshii.location.all
81
+ ```
82
+ POST /locations
83
+ ```ruby
84
+ Doshii.location.create do |params|
85
+ params[:name] = 'Chickens R Us'
86
+ params[:mobility] = 'fixed'
87
+ params[:availability] = 'closed'
88
+ params[:address_line1] = '608 St Kilda Rd'
89
+ # see the official api page for complete list of available params
90
+ end
91
+ ```
92
+
93
+ **ORDERS**
94
+
95
+ GET /orders/:orderId
96
+ ```ruby
97
+ Doshii.order.find :order_id
98
+ ```
99
+ POST /orders/:checkinId
100
+ ```ruby
101
+ Doshii.order.create :checkin_id do |params|
102
+ params[:status] = 'pending'
103
+ params[:items] = [
104
+ {
105
+ name: 'Toasted Sourdough Bread & Eggs'
106
+ description: 'Just ye old classic'
107
+ # ...
108
+ }
109
+ # ...
110
+ ]
111
+ # see the official api page for complete list of available params
112
+ end
113
+ ```
114
+ PUT /orders/:orderId
115
+ ```ruby
116
+ # sample - consumer wants to pay
117
+ Doshii.order.update :order_id do |params|
118
+ params[:tip] = '0'
119
+ params[:status] = 'ready to pay'
120
+ params[:updatedAt] = '2015-05-20T23:32:58.526Z'
121
+ end
122
+ # sample - payment has been processed and order is updated to paid
123
+ Doshii.order.update :order_id do |params|
124
+ params[:tip] = '0'
125
+ params[:status] = 'ready to pay'
126
+ params[:updatedAt] = '2015-05-20T23:32:58.526Z'
127
+ params[:transactionId] = '123'
128
+ params[:invoiceId] = '123'
129
+ end
130
+ ```
131
+
132
+ **PRODUCTS**
133
+
134
+ GET /products/:locationId
135
+ ```ruby
136
+ Doshii.product.find :location_id
137
+ ```
138
+
139
+
140
+ ## Development
141
+
142
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
143
+
144
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
145
+
146
+ ## Contributing
147
+
148
+ 1. Fork it ( https://github.com/[my-github-username]/doshii/fork )
149
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
150
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
151
+ 4. Push to the branch (`git push origin my-new-feature`)
152
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "doshii"
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
@@ -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
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'doshii/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "doshii"
8
+ spec.version = Doshii::VERSION
9
+ spec.authors = ["Romel Campos"]
10
+ spec.email = ["rcoolah@gmail.com"]
11
+
12
+ spec.summary = %q{Gem to wrap Doshii API}
13
+ spec.description = %q{Gem to wrap Doshii API}
14
+ spec.homepage = "https://github.com/devrc-trise/doshii"
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 "bundler", "~> 1.9"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.7.0"
33
+ spec.add_development_dependency "vcr", "~> 2.9.3"
34
+ spec.add_development_dependency "webmock", "~> 1.21.0"
35
+
36
+ spec.add_dependency "faraday", "~> 0.9.1"
37
+ spec.add_dependency "faraday_middleware", "~> 0.10.0"
38
+ spec.add_dependency "json", "~> 1.8.3"
39
+ end
@@ -0,0 +1,9 @@
1
+ require 'json'
2
+
3
+ require 'doshii/version'
4
+ require 'doshii/configuration'
5
+ require 'doshii/client'
6
+
7
+ module Doshii
8
+ extend Configuration
9
+ end
@@ -0,0 +1,34 @@
1
+ require 'doshii/resource'
2
+
3
+ module Doshii
4
+ class << self
5
+ def checkin
6
+ resource 'checkins'
7
+ end
8
+
9
+ def location
10
+ resource 'locations'
11
+ end
12
+
13
+ def order
14
+ resource 'orders'
15
+ end
16
+
17
+ def product
18
+ resource 'products'
19
+ end
20
+
21
+ def options
22
+ Hash[*Configuration::VALID_CONFIG_KEYS.map { |key| [key, value(key)] }.flatten]
23
+ end
24
+
25
+ def resource(url)
26
+ Doshii::Resource.new url, options
27
+ end
28
+
29
+ def value(key)
30
+ key = "@#{key.to_s}".to_sym
31
+ Doshii.instance_variable_get(key)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ module Doshii
2
+ module Configuration
3
+ VALID_CONNECTION_KEYS = [:endpoint, :verify_ssl, :version].freeze
4
+ VALID_OPTIONS_KEYS = [:client_id, :client_secret].freeze
5
+ VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
6
+
7
+ DEFAULT_ENDPOINT = 'https://alphasandbox.doshii.co/partner/api'
8
+ DEFAULT_VERIFY_SSL = false
9
+ DEFAULT_VERSION = 'v1'
10
+
11
+ DEFAULT_CLIENT_ID = '369c27e8d884e0b54e56035b41eed4b07b0fc59091907418f0368ab643a4ad31'
12
+ DEFAULT_CLIENT_SECRET = 'c0c0441e9bcc671dff9beb8e2a16fb43ed392f8c9a029dc8075cb71b1ac87e5f'
13
+
14
+ attr_accessor *VALID_CONFIG_KEYS
15
+
16
+ def self.extended(base)
17
+ base.reset
18
+ end
19
+
20
+ def reset
21
+ @endpoint = DEFAULT_ENDPOINT
22
+ @verify_ssl = DEFAULT_VERIFY_SSL
23
+ @client_id = DEFAULT_CLIENT_ID
24
+ @client_secret = DEFAULT_CLIENT_SECRET
25
+ @version = DEFAULT_VERSION
26
+ end
27
+
28
+ def configure
29
+ yield self
30
+ end
31
+
32
+ def options
33
+ Hash[*VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten]
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,38 @@
1
+ require 'base64'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+
5
+ module Doshii
6
+ module Connection
7
+ protected
8
+
9
+ def http_connection
10
+ @http_connection ||=
11
+ Faraday.new("#{endpoint}/#{version}/") do |faraday|
12
+ faraday.response :logger
13
+ faraday.adapter Faraday.default_adapter
14
+ faraday.use Faraday::Response::ParseJson
15
+
16
+ faraday.headers['Authorization'] = "Basic #{base64_encoded_key}"
17
+ faraday.headers['Content-Type'] = 'application/json'
18
+ faraday.ssl['verify'] = verify_ssl
19
+ end
20
+ end
21
+
22
+ def request(method, url, query = {}, &block)
23
+ body = Hash.new
24
+ yield body if block_given?
25
+ http_connection.send(method) do |req|
26
+ req.url url, query
27
+ req.body = JSON.generate(body)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def base64_encoded_key
34
+ key = "#{client_id}:#{client_secret}"
35
+ Base64.urlsafe_encode64 key
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ require 'doshii/connection'
2
+
3
+ module Doshii
4
+ class Resource
5
+ include Connection
6
+
7
+ attr_writer :url
8
+ attr_accessor *Configuration::VALID_CONFIG_KEYS
9
+
10
+ def initialize(url, options = {})
11
+ @url = url
12
+ merged_options = Doshii.options.merge(options)
13
+ Configuration::VALID_CONFIG_KEYS.each do |key|
14
+ send("#{key}=", merged_options[key])
15
+ end
16
+ end
17
+
18
+ def all
19
+ request :get, @url
20
+ end
21
+
22
+ def create(id = nil, query = {}, &block)
23
+ url = id.nil? ? @url : "#{@url}/#{id}"
24
+ request :post, url, query, &block
25
+ end
26
+
27
+ def delete(id)
28
+ request :delete, "#{@url}/#{id}"
29
+ end
30
+
31
+ def find(id)
32
+ request :get, "#{@url}/#{id}"
33
+ end
34
+
35
+ def update(id, query = {}, &block)
36
+ request :put, "#{@url}/#{id}", query, &block
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Doshii
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,9 @@
1
+ module Doshii
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def copy_initializer_file
6
+ copy_file 'doshii.rb', 'config/initializers/doshii.rb'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ Doshii.configure do |config|
2
+ # you might want to set these values in environment files
3
+ config.client_id = '369c27e8d884e0b54e56035b41eed4b07b0fc59091907418f0368ab643a4ad31'
4
+ config.client_secret = 'c0c0441e9bcc671dff9beb8e2a16fb43ed392f8c9a029dc8075cb71b1ac87e5f'
5
+ config.endpoint = 'https://alphasandbox.doshii.co/partner/api'
6
+ config.verify_ssl = false
7
+ config.version = 'v1'
8
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doshii
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Romel Campos
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 5.7.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 5.7.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.9.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.9.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.21.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.21.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.9.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday_middleware
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.10.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.10.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: json
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.8.3
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.8.3
125
+ description: Gem to wrap Doshii API
126
+ email:
127
+ - rcoolah@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - bin/console
139
+ - bin/setup
140
+ - doshii.gemspec
141
+ - lib/doshii.rb
142
+ - lib/doshii/client.rb
143
+ - lib/doshii/configuration.rb
144
+ - lib/doshii/connection.rb
145
+ - lib/doshii/resource.rb
146
+ - lib/doshii/version.rb
147
+ - lib/generators/doshii/install_generator.rb
148
+ - lib/generators/doshii/templates/doshii.rb
149
+ homepage: https://github.com/devrc-trise/doshii
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.8
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Gem to wrap Doshii API
173
+ test_files: []