bliss-client 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3229d8ee51a3a4b0cb8384c2291c72813c3187c4
4
+ data.tar.gz: 6477ff26a3e5fb74afa512d7b700d92dd0805708
5
+ SHA512:
6
+ metadata.gz: ddb51650cc63b23c412f94887f0c4e7f82547757c84fb8b59e42caeed75a90a1923155733c814ee54771c5d55e7bf55d084b424037883ed9d10e20bbc922eacc
7
+ data.tar.gz: 2bb2a3320871c9b258b2672823ddc13535b92c297b7bbeadf5ecee4d11bf7588689fc2f254fc2c803fd4092d799873eeb89905ba7c8570f928eb07aa99fcd678
data/.env.example ADDED
@@ -0,0 +1,3 @@
1
+ BLISS_SERVER=http://localhost:3000
2
+ BLISS_CLIENT_ID=yourID
3
+ BLISS_CLIENT_SECRET=youSecret
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .env
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.3
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bliss-client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Fadendaten GmbH
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,205 @@
1
+ # Bliss::Client [![Build Status](https://semaphoreci.com/api/v1/projects/da4b4bec-8734-44c1-afe0-c13d0597fe5b/619317/badge.svg)](https://semaphoreci.com/fadendaten/bliss-client)
2
+
3
+ Bliss API Ruby client.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'bliss-client', git: 'git@github.com:fadendaten/bliss-client.git', tag: 'v1.2.0'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ bundle
17
+ ```
18
+
19
+ ### Authorization
20
+
21
+ The client requires the following environment variables to be set:
22
+
23
+ ```bash
24
+ BLISS_SERVER=http://sv96.aarboard.ch
25
+ BLISS_CLIENT_ID=34osdljwosdf...
26
+ BLISS_CLIENT_SECRET=24ljsdfo8t34...
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ### Creating a Webshop order
32
+
33
+ ```ruby
34
+ order = Bliss::Client::Order.create(
35
+ type: :webshop,
36
+ blizzard_customer_id: 4,
37
+ items: [
38
+ {
39
+ article_id: 3456, # Bliss article id
40
+ quantity: 2,
41
+ price_value: 35.20,
42
+ price_currency: 'CHF'
43
+ },
44
+ {
45
+ article_id: 18462,
46
+ quantity: 1,
47
+ price_value: 120,
48
+ price_currency: 'CHF'
49
+ }
50
+ ],
51
+ delivery_address: {
52
+ salutation: 'Mr Spongebob Squarepants',
53
+ line_1: 'Ananas 3', # optionally pass line_2 and line_3
54
+ zip_code: '12345',
55
+ city: 'Bikini Bottom',
56
+ country_iso3: 'USA'
57
+ },
58
+ remote_id: 234, # the id of the local Webshop order
59
+ )
60
+
61
+ order.id # => id of the Bliss Webshop order
62
+ ```
63
+
64
+ ### Fetching collections
65
+
66
+ Collections and their children model the product catalogue of NILE. The
67
+ `Bliss::Client::Collection` provides a way to fetch that data.
68
+
69
+ #### Fetching all collections without any children with `.all`
70
+
71
+ ```ruby
72
+ collections = Bliss::Client::Collection.all
73
+ ```
74
+
75
+ This can be useful for fetching all basic information quickly and then use the
76
+ IDs of some collections to get more info via `.find` (see below).
77
+
78
+ #### Fetch specific collections with `.find`
79
+
80
+ ```ruby
81
+ ids = [88, 90, 91, 21]
82
+ collections = Bliss::Client::Collection.find ids
83
+ ```
84
+
85
+ #### Fetch specific collections and include children with the `include_<whatever>` options
86
+
87
+ ```ruby
88
+ ids = [88, 90, 91, 21]
89
+ collections = Bliss::Client::Collection.find(
90
+ ids,
91
+ include_programs: true,
92
+ include_styles: true,
93
+ include_articles: true
94
+ )
95
+
96
+ collections.each do |collection|
97
+ # Access programs with Collection#programs.
98
+ collection.programs.each do |program|
99
+ # Access styles with Program#styles.
100
+ program.styles # ...
101
+ end
102
+ end
103
+ ```
104
+
105
+ #### Fetching all necessary data for webshop4
106
+
107
+ ```ruby
108
+ # Make sure we know about all sizes
109
+ Bliss::Client::Size.all.each { # create size options type }
110
+
111
+ # Say webshop4 needs to know about collection 88, 89 and 90.
112
+ collection_ids = [88, 89, 90]
113
+
114
+ # We want EVERYTHING!!
115
+ options = {
116
+ include_programs: true,
117
+ include_colors: true,
118
+ include_styles: true,
119
+ include_articles: true,
120
+ include_prices: true
121
+ }
122
+
123
+ collections = Bliss::Client::Collection.find(collection_ids, options)
124
+
125
+ # Traverse the structure with #each and do whatever you want, e.g.
126
+ collections.each do |collection|
127
+
128
+ collection.keylooks.each { # create keylook (aka weblook) }
129
+ collection.studiolooks.each { # create studiolook }
130
+
131
+ collection.programs.each do |program|
132
+
133
+ program.colors.each { # create options types }
134
+
135
+ program.styles.each do |styles|
136
+
137
+ styles.each do |style|
138
+ # create product
139
+
140
+ style.articles.each do |article|
141
+ # create product variant
142
+
143
+ # NOTE: that this will return the article ID blizzard is interested in
144
+ article.legacy_id
145
+ end
146
+
147
+ # access prices
148
+ [:chf, :eur].each do |currency|
149
+ # current prices (may be reduced)
150
+ style.sales_price(currency)
151
+ style.purchase_price(currency)
152
+
153
+ # original prices (non-reduced)
154
+ style.original_sales_price(currency)
155
+ style.original_purchase_price(currency)
156
+
157
+ # find out whether the style is discounted, i.e. sold at a reduced
158
+ # price
159
+ style.discounted?(currency)
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
165
+ ```
166
+
167
+ ## Development
168
+
169
+ To install the dependencies and setup config files:
170
+
171
+ ```bash
172
+ bin/setup
173
+ ```
174
+
175
+ To run the tests:
176
+
177
+ ```bash
178
+ rake
179
+ ```
180
+
181
+ To see faraday output while running tests:
182
+
183
+ ```bash
184
+ BLISS_CLIENT_DEBUG=true rake
185
+ ```
186
+
187
+ For an interactive prompt:
188
+
189
+ ```
190
+ bin/console
191
+ ```
192
+
193
+ To install this gem onto your local machine, run `bundle exec rake install`. To
194
+ release a new version, update the version number in `version.rb`, and then run
195
+ `bundle exec rake release`, which will create a git tag for the version, push
196
+ git commits and tags, and push the `.gem` file to
197
+ [rubygems.org](https://rubygems.org).
198
+
199
+ ## Contributing
200
+
201
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fadendaten/bliss-client.
202
+
203
+ ## License
204
+
205
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bliss/client"
5
+ require "dotenv"
6
+ require "pry"
7
+
8
+ Dotenv.load
9
+
10
+ # You can add fixtures and/or initialization code here to make experimenting
11
+ # with your gem easier. You can also use a different console, if you like.
12
+
13
+ Pry.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
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bliss/client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bliss-client"
8
+ spec.version = Bliss::Client::VERSION
9
+ spec.authors = ["Fadendaten GmbH"]
10
+ spec.email = ["support@fadendaten.ch"]
11
+
12
+ spec.summary = "Bliss API client library"
13
+ spec.homepage = "http://www.fadendaten.ch/"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ # end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency "faraday", "~> 0.9.2"
30
+ spec.add_runtime_dependency "faraday_middleware", "~> 0.10.0"
31
+ spec.add_runtime_dependency "typhoeus", "~> 0.8.0"
32
+ spec.add_runtime_dependency 'virtus', '~> 1.0.5'
33
+ spec.add_runtime_dependency 'activemodel', '~> 4.2', '>= 3.2'
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.10"
36
+ spec.add_development_dependency "dotenv", "~> 2.0.2"
37
+ spec.add_development_dependency "minitest", "~> 5.8.3"
38
+ spec.add_development_dependency "pry", "~> 0.10.3"
39
+ spec.add_development_dependency "pry-byebug", "~> 3.3.0"
40
+ spec.add_development_dependency "pry-doc", "~> 0.8.0"
41
+ spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "vcr", "~> 3.0.0"
43
+ end
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:3000/oauth/token
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"grant_type":"client_credentials","client_id":"938f4d9d2dc0e5e083b9b7522df523ec77815298e489181c07b34dcc98912c93","client_secret":"d3aa293c490e6713eb0783a8e8e6894f33c4886d61b0f5522d46b29d68850dc2"}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message:
18
+ headers:
19
+ X-Frame-Options:
20
+ - SAMEORIGIN
21
+ X-XSS-Protection:
22
+ - 1; mode=block
23
+ X-Content-Type-Options:
24
+ - nosniff
25
+ Cache-Control:
26
+ - no-store, must-revalidate, private, max-age=0
27
+ Pragma:
28
+ - no-cache
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ X-Request-Id:
32
+ - 489fc6ea-bddc-4d1a-ac7e-04965fb6a03d
33
+ X-Runtime:
34
+ - '0.029444'
35
+ Set-Cookie:
36
+ - __profilin=p%3Dt; path=/, __profilin=p%3Dt; path=/, __profilin=p%3Dt; path=/
37
+ X-MiniProfiler-Ids:
38
+ - '["y7bpuf1xhei7uqegwfpd","qkro8e6gzily83mtdaos","g87ldxy2frx3qj59nz26","7ktv8sj5ywkozy0swrry","7xhjbmkhk6ez3k3ojgu1","hzz9f7p4sj9f7nvfpj03","m3j6ppn7tv85th7h9v9b","8zffept08saqj5zbezni","jalp8l0w3khlngo9kbvr","pd4kxfx0jgjlgf6rd0d"]'
39
+ Connection:
40
+ - close
41
+ Server:
42
+ - thin
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"access_token":"f0e0d91cd53b498889ac91c189f889dac53f9f4d03c87e251dd9496c12aa4141","token_type":"bearer","expires_in":7200,"created_at":1453903541}'
46
+ http_version:
47
+ recorded_at: Wed, 27 Jan 2016 14:05:41 GMT
48
+ recorded_with: VCR 3.0.0
@@ -0,0 +1,91 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:3000/oauth/token
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"grant_type":"client_credentials","client_id":"938f4d9d2dc0e5e083b9b7522df523ec77815298e489181c07b34dcc98912c93","client_secret":"d3aa293c490e6713eb0783a8e8e6894f33c4886d61b0f5522d46b29d68850dc2"}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Content-Type:
13
+ - application/json
14
+ response:
15
+ status:
16
+ code: 200
17
+ message:
18
+ headers:
19
+ X-Frame-Options:
20
+ - SAMEORIGIN
21
+ X-XSS-Protection:
22
+ - 1; mode=block
23
+ X-Content-Type-Options:
24
+ - nosniff
25
+ Cache-Control:
26
+ - no-store, must-revalidate, private, max-age=0
27
+ Pragma:
28
+ - no-cache
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ X-Request-Id:
32
+ - 624dd1ee-d61a-4f18-8afb-c20e0b6fa819
33
+ X-Runtime:
34
+ - '0.027402'
35
+ Set-Cookie:
36
+ - __profilin=p%3Dt; path=/, __profilin=p%3Dt; path=/, __profilin=p%3Dt; path=/
37
+ X-MiniProfiler-Ids:
38
+ - '["97nnr7ynkluvg1cy2omx","qkro8e6gzily83mtdaos","g87ldxy2frx3qj59nz26","7ktv8sj5ywkozy0swrry","7xhjbmkhk6ez3k3ojgu1","hzz9f7p4sj9f7nvfpj03","m3j6ppn7tv85th7h9v9b","8zffept08saqj5zbezni","jalp8l0w3khlngo9kbvr","pd4kxfx0jgjlgf6rd0d"]'
39
+ Connection:
40
+ - close
41
+ Server:
42
+ - thin
43
+ body:
44
+ encoding: UTF-8
45
+ string: '{"access_token":"17023f6443564cc958801a18f708347a616d4dacc8cc62966b36a3341c3c0b65","token_type":"bearer","expires_in":7200,"created_at":1453903541}'
46
+ http_version:
47
+ recorded_at: Wed, 27 Jan 2016 14:05:41 GMT
48
+ - request:
49
+ method: post
50
+ uri: http://localhost:3000/api/v1/orders?access_token=17023f6443564cc958801a18f708347a616d4dacc8cc62966b36a3341c3c0b65
51
+ body:
52
+ encoding: UTF-8
53
+ string: '{"blizzard_customer_id":4,"type":"webshop","items":[{"article_id":3456,"price_value":"0.352E2","price_currency":"CHF","quantity":2},{"article_id":18462,"price_value":"0.12E3","price_currency":"CHF","quantity":1}],"delivery_address":{"salutation":"Mr
54
+ Spongebob Squarepants","line_1":"Ananas 3","line_2":null,"line_3":null,"zip_code":"12345","city":"Bikini
55
+ Bottom","country_iso3":"CHE"},"remote_id":234}'
56
+ headers:
57
+ User-Agent:
58
+ - Faraday v0.9.2
59
+ Authorization:
60
+ - Token token="17023f6443564cc958801a18f708347a616d4dacc8cc62966b36a3341c3c0b65"
61
+ Content-Type:
62
+ - application/json
63
+ response:
64
+ status:
65
+ code: 201
66
+ message:
67
+ headers:
68
+ Content-Type:
69
+ - application/json
70
+ Content-Length:
71
+ - '48'
72
+ ETag:
73
+ - W/"628b5e68d4b0eea91671f59a31cc6080"
74
+ Cache-Control:
75
+ - max-age=0, private, must-revalidate
76
+ X-Request-Id:
77
+ - dfb2c70b-c4ab-46ee-bb7f-aaa4303850d1
78
+ X-Runtime:
79
+ - '0.153022'
80
+ Set-Cookie:
81
+ - __profilin=p%3Dt; path=/, __profilin=p%3Dt; path=/
82
+ Connection:
83
+ - keep-alive
84
+ Server:
85
+ - thin
86
+ body:
87
+ encoding: UTF-8
88
+ string: '{"id":25122,"created_at":"2016-01-27T14:05:41Z"}'
89
+ http_version:
90
+ recorded_at: Wed, 27 Jan 2016 14:05:41 GMT
91
+ recorded_with: VCR 3.0.0