buckybox-api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +18 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/buckybox-api.gemspec +25 -0
- data/lib/buckybox/api.rb +126 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: edd5b4d1bd186410202639fa8791cf2dcfe4c27a
|
4
|
+
data.tar.gz: 660e17e071952e8083c7999e6950fef65e88d335
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 82568111a1a539263b93bd3fbdfd6999639dd5ea2133ae4ce621cc688ae7a79ae45a4738f376f091a51bc741f070777a834b87ebbe876f583ded4f55e801b3f9
|
7
|
+
data.tar.gz: 05cbe59000adbebfc56d36222e4192cb9c7738530fb120f7ef1dc06c6225c136bd8660c75f8fcf41aa0cc01d8044d4f0c638b00d82a8b3ac91e6963883a5d76e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
BuckyBox::API RubyGem
|
2
|
+
Copyright (C) 2014 Bucky Box
|
3
|
+
|
4
|
+
LGPLv3 License
|
5
|
+
|
6
|
+
This program is free software: you can redistribute it and/or modify
|
7
|
+
it under the terms of the GNU Lesser General Public License as published by
|
8
|
+
the Free Software Foundation, either version 3 of the License, or
|
9
|
+
(at your option) any later version.
|
10
|
+
|
11
|
+
This program is distributed in the hope that it will be useful,
|
12
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
GNU Lesser General Public License for more details.
|
15
|
+
|
16
|
+
You should have received a copy of the GNU Lesser General Public License
|
17
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# BuckyBox::API
|
2
|
+
|
3
|
+
[![Dependency Status](http://img.shields.io/gemnasium/buckybox/buckybox-api-ruby.svg)](https://gemnasium.com/buckybox/buckybox-api-ruby)
|
4
|
+
[![Code Climate](http://img.shields.io/codeclimate/github/buckybox/buckybox-api-ruby.svg)](https://codeclimate.com/github/buckybox/buckybox-api-ruby)
|
5
|
+
[![Gem Version](http://img.shields.io/gem/v/buckybox-api.svg)](https://rubygems.org/gems/buckybox-api)
|
6
|
+
|
7
|
+
https://api.buckybox.com/docs
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require "buckybox/api"
|
13
|
+
|
14
|
+
class YourClass
|
15
|
+
|
16
|
+
def boxes
|
17
|
+
api.boxes
|
18
|
+
end
|
19
|
+
|
20
|
+
private def api
|
21
|
+
@api ||= BuckyBox::API.new(
|
22
|
+
"API-Key" => "your API key",
|
23
|
+
"API-Secret" => "your API secret",
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
YourClass.new.boxes #=> some JSON
|
30
|
+
```
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
LGPLv3
|
35
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "buckybox-api"
|
7
|
+
spec.version = "1.0.0"
|
8
|
+
spec.authors = ["Cédric Félizard"]
|
9
|
+
spec.email = ["cedric@felizard.fr"]
|
10
|
+
spec.summary = %q{RubyGem wrapper for the Bucky Box API}
|
11
|
+
spec.description = "#{spec.summary} - https://api.buckybox.com/docs"
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "LGPLv3"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "httparty", "~> 0.13.1"
|
21
|
+
spec.add_dependency "super_recursive_open_struct", "~> 1.0.2"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
data/lib/buckybox/api.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "super_recursive_open_struct"
|
3
|
+
|
4
|
+
module BuckyBox
|
5
|
+
module API
|
6
|
+
ResponseError = Class.new(Exception)
|
7
|
+
|
8
|
+
module_function def new(headers)
|
9
|
+
api = Class.new do
|
10
|
+
include HTTParty
|
11
|
+
format :json
|
12
|
+
base_uri "https://api.buckybox.com/v0"
|
13
|
+
# base_uri "http://api.buckybox.dev:3000/v0"
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def boxes(params = {embed: "extras,images,box_items"}, options = {})
|
17
|
+
query :get, "/boxes", params, options, price: CrazyMoney
|
18
|
+
end
|
19
|
+
|
20
|
+
def box(id, params = {embed: "extras,images,box_items"}, options = {})
|
21
|
+
query :get, "/boxes/#{id}", params, options, price: CrazyMoney
|
22
|
+
end
|
23
|
+
|
24
|
+
def delivery_services(params = {}, options = {})
|
25
|
+
query :get, "/delivery_services", params, options, fee: CrazyMoney
|
26
|
+
end
|
27
|
+
|
28
|
+
def delivery_service(id, params = {}, options = {})
|
29
|
+
query :get, "/delivery_services/#{id}", params, options, fee: CrazyMoney
|
30
|
+
end
|
31
|
+
|
32
|
+
def webstore
|
33
|
+
query :get, "/webstore"
|
34
|
+
end
|
35
|
+
|
36
|
+
def customer(id, params = {}, options = {})
|
37
|
+
query :get, "/customers/#{id}", params, options, account_balance: CrazyMoney
|
38
|
+
end
|
39
|
+
|
40
|
+
def customers(params = {}, options = {})
|
41
|
+
query :get, "/customers", params, options, account_balance: CrazyMoney
|
42
|
+
end
|
43
|
+
|
44
|
+
def authenticate_customer(params = {}, options = {})
|
45
|
+
query :post, "/customers/sign_in", params, options
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_or_update_customer(json_customer)
|
49
|
+
customer = JSON.parse(json_customer)
|
50
|
+
|
51
|
+
if customer['id']
|
52
|
+
query :put, "/customers/#{customer['id']}", json_customer # TODO: replace by :patch
|
53
|
+
else
|
54
|
+
query :post, "/customers", json_customer
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_order(json_order)
|
59
|
+
query :post, "/orders", json_order
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def check_response!(response)
|
65
|
+
unless [200, 201].include? response.code
|
66
|
+
message = response.parsed_response["message"] || response.parsed_response
|
67
|
+
message = "Error #{response.code} - #{message}"
|
68
|
+
raise ResponseError, message
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def query(type, uri, params = {}, options = {}, types = {})
|
73
|
+
options = {
|
74
|
+
as_object: true
|
75
|
+
}.merge(options)
|
76
|
+
|
77
|
+
hash = query_cache(type, uri, params, types)
|
78
|
+
|
79
|
+
if options[:as_object]
|
80
|
+
SuperRecursiveOpenStruct.new(hash)
|
81
|
+
else
|
82
|
+
hash
|
83
|
+
end.freeze
|
84
|
+
end
|
85
|
+
|
86
|
+
def query_cache(type, uri, params, types)
|
87
|
+
query_fresh = -> {
|
88
|
+
params_key = (type == :get ? :query : :body)
|
89
|
+
response = public_send(type, uri, params_key => params)
|
90
|
+
check_response!(response)
|
91
|
+
parsed_response = response.parsed_response
|
92
|
+
add_types(parsed_response, types)
|
93
|
+
}
|
94
|
+
|
95
|
+
if type == :get # NOTE: only cache GET method
|
96
|
+
cache_key = [uri, params.to_query].join
|
97
|
+
|
98
|
+
@cache ||= {}
|
99
|
+
@cache[cache_key] ||= query_fresh.call
|
100
|
+
else
|
101
|
+
query_fresh.call
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def add_types(object, types)
|
106
|
+
if object.is_a?(Array)
|
107
|
+
object.map { |item| add_types(item, types) }
|
108
|
+
else
|
109
|
+
types.each do |attribute, type|
|
110
|
+
attribute = attribute.to_s
|
111
|
+
|
112
|
+
new_value = type.new object.fetch(attribute)
|
113
|
+
object.store(attribute, new_value)
|
114
|
+
end
|
115
|
+
|
116
|
+
object
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
api.headers(headers)
|
123
|
+
api
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: buckybox-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cédric Félizard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: super_recursive_open_struct
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: RubyGem wrapper for the Bucky Box API - https://api.buckybox.com/docs
|
70
|
+
email:
|
71
|
+
- cedric@felizard.fr
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- buckybox-api.gemspec
|
82
|
+
- lib/buckybox/api.rb
|
83
|
+
homepage: ''
|
84
|
+
licenses:
|
85
|
+
- LGPLv3
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.2.2
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: RubyGem wrapper for the Bucky Box API
|
107
|
+
test_files: []
|