LYBC 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LYBC.gemspec +35 -0
- data/README.md +54 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/mock_server +3 -0
- data/bin/setup +8 -0
- data/lib/LYBC.rb +6 -0
- data/lib/LYBC/client.rb +99 -0
- data/lib/LYBC/version.rb +3 -0
- data/mock_server.rb +48 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c50059e5bf77bef071c907b08558fe93f484bcd1
|
4
|
+
data.tar.gz: 6492c21948f3d5dc3e831193b0f8b1ddd4c6073f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 429518da2e59cf1ffbcccc112a12d73c2ca33bddaefd397dfc35b786313f4ff37b102bae258735a67c3d36257d893af7b3e565895887e29a0d4c2f003641d52b
|
7
|
+
data.tar.gz: 4af7319a7323b8fa0760b4c33b73668fef87c5c0bbb5bd144b69cb5c25cd9710170e20d2dcc3663132a7a5f3448b7ff07b9b3ae99bc58a1e911f1ed9bc57a8b7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at marios@artime.gr. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LYBC.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'LYBC/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "LYBC"
|
8
|
+
spec.version = LYBC::VERSION
|
9
|
+
spec.authors = ["Marios Antonoudiou"]
|
10
|
+
spec.email = ["marios@artime.gr"]
|
11
|
+
|
12
|
+
spec.summary = "Ruby client for LYBC Greece"
|
13
|
+
spec.homepage = "https://github.com/artime-advertising/LYBC-ruby"
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
|
+
# if spec.respond_to?(:metadata)
|
18
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
19
|
+
# else
|
20
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
21
|
+
# end
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
spec.add_development_dependency "byebug", "~> 9.0.5"
|
32
|
+
spec.add_development_dependency "sinatra", "~> 1.4.7"
|
33
|
+
spec.add_runtime_dependency "faraday", "~> 0.9.2"
|
34
|
+
|
35
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# LYBC client
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/artime-advertising/LYBC-ruby.svg?branch=master)](https://travis-ci.org/artime-advertising/LYBC-ruby)
|
4
|
+
|
5
|
+
This is a client for The Body Shop Greece LYBC API. It is written in Ruby and has very few dependencies.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'LYBC', :git => 'git@github.com:artime-advertising/LYBC-ruby.git'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
This libary tries to resemble CIP's js (in-browser) client.
|
22
|
+
|
23
|
+
Construct the client via:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
lybc_client = LYBC::Client.new("session_id")
|
27
|
+
```
|
28
|
+
|
29
|
+
Then make calls:
|
30
|
+
```
|
31
|
+
> lybc_client.registerSession
|
32
|
+
=> {"action"=>"registerSession", "message"=>"Session expired", "sessionID"=>"session_id", "status"=>1}
|
33
|
+
```
|
34
|
+
|
35
|
+
### Available methods:
|
36
|
+
|
37
|
+
``` ruby
|
38
|
+
> lybc_client.registerSession('session_id')
|
39
|
+
> lybc_client.getAssociation()
|
40
|
+
> lybc_client.getSelectedCoupons()
|
41
|
+
> lybc_client.cashSelectedCoupons()
|
42
|
+
```
|
43
|
+
|
44
|
+
All methods have a bang-ending alternative, ie `lybc_client.getAssociation!` which throws an error in case an error status returns.
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
49
|
+
|
50
|
+
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/artime-advertising/LYBC-ruby.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "LYBC"
|
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
|
data/bin/mock_server
ADDED
data/bin/setup
ADDED
data/lib/LYBC.rb
ADDED
data/lib/LYBC/client.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'faraday'
|
3
|
+
|
4
|
+
module LYBC
|
5
|
+
|
6
|
+
@@api_endpoint = "http://api.rel.lybc.cipsrv.xyz/actionresult/ecomm"
|
7
|
+
def self.api_endpoint
|
8
|
+
@@api_endpoint
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.api_endpoint=(endpoint)
|
12
|
+
@@api_endpoint = endpoint
|
13
|
+
end
|
14
|
+
|
15
|
+
@@api_prefix = ""
|
16
|
+
def self.api_prefix
|
17
|
+
@@api_prefix
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.api_prefix=(prefix)
|
21
|
+
raise("API prefix should start with /") unless (prefix[0] == '/')
|
22
|
+
@@api_prefix = prefix
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.api_url
|
26
|
+
"#{@@api_endpoint}"
|
27
|
+
end
|
28
|
+
|
29
|
+
class Client
|
30
|
+
attr_accessor :session_id
|
31
|
+
|
32
|
+
def initialize(session_id)
|
33
|
+
@session_id = session_id
|
34
|
+
@conn = Faraday.new()
|
35
|
+
end
|
36
|
+
|
37
|
+
def registerSession(associationID = "")
|
38
|
+
body = {
|
39
|
+
'sessionID' => @session_id.to_s,
|
40
|
+
'action' => 'registerSession',
|
41
|
+
'data' => {
|
42
|
+
'associationID' => associationID.to_s,
|
43
|
+
'expirationDate' => "2017-2-24"
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
response = @conn.post(LYBC.api_endpoint, body.to_json, 'Content-Type' => 'application/json')
|
48
|
+
JSON.parse(response.body)
|
49
|
+
end
|
50
|
+
|
51
|
+
def getAssociation
|
52
|
+
body = {
|
53
|
+
'sessionID' => @session_id,
|
54
|
+
'action' => 'getAssociation',
|
55
|
+
'data' => {}
|
56
|
+
}
|
57
|
+
|
58
|
+
response = @conn.post("#{LYBC.api_endpoint}", body.to_json, 'Content-Type' => 'application/json')
|
59
|
+
JSON.parse(response.body)
|
60
|
+
end
|
61
|
+
|
62
|
+
def getSelectedCoupons
|
63
|
+
body = {
|
64
|
+
'sessionID' => @session_id,
|
65
|
+
'action' => 'getSelectedCoupons',
|
66
|
+
'data' => {}
|
67
|
+
}
|
68
|
+
|
69
|
+
response = @conn.post("#{LYBC.api_url}", body.to_json, 'Content-Type' => 'application/json')
|
70
|
+
JSON.parse(response.body)
|
71
|
+
end
|
72
|
+
|
73
|
+
def cashSelectedCoupons
|
74
|
+
body = {
|
75
|
+
'sessionID' => @session_id,
|
76
|
+
'action' => 'cashSelectedCoupons',
|
77
|
+
'data' => {}
|
78
|
+
}
|
79
|
+
|
80
|
+
response = @conn.post("#{LYBC.api_url}", body.to_json, 'Content-Type' => 'application/json')
|
81
|
+
JSON.parse(response.body)
|
82
|
+
end
|
83
|
+
|
84
|
+
[:registerSession, :getAssociation, :getSelectedCoupons, :cashSelectedCoupons].each do |method|
|
85
|
+
define_method("#{method}!".to_sym) do
|
86
|
+
response = self.send(method)
|
87
|
+
raise Exception.new('Response was not successful') unless is_successful?(response)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def is_successful?(parsed_response)
|
94
|
+
parsed_response['status'] == 1
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
data/lib/LYBC/version.rb
ADDED
data/mock_server.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'byebug'
|
4
|
+
|
5
|
+
register_session_response = {
|
6
|
+
"status" => 1,
|
7
|
+
"sessionID" => 200,
|
8
|
+
"action" => "registerSession"
|
9
|
+
}
|
10
|
+
|
11
|
+
get_association_response = {
|
12
|
+
"status" => 1,
|
13
|
+
"sessionID" => 200,
|
14
|
+
"action" => "getAssociation",
|
15
|
+
"associationID" => 231
|
16
|
+
}
|
17
|
+
|
18
|
+
get_selected_coupons_response = {
|
19
|
+
"status" => 1,
|
20
|
+
"sessionID" => 200,
|
21
|
+
"action" => "getAssociation",
|
22
|
+
"coupons" => []
|
23
|
+
}
|
24
|
+
|
25
|
+
cash_selected_coupons_response = {
|
26
|
+
"status" => 1,
|
27
|
+
"sessionID" => 200,
|
28
|
+
"action" => "registerSession"
|
29
|
+
}
|
30
|
+
|
31
|
+
response_map = {
|
32
|
+
'registerSession' => register_session_response,
|
33
|
+
'getAssociation' => get_association_response,
|
34
|
+
'getSelectedCoupons' => get_selected_coupons_response,
|
35
|
+
'cashSelectedCoupons' => cash_selected_coupons_response
|
36
|
+
}
|
37
|
+
|
38
|
+
post '/action.php' do
|
39
|
+
request_body = JSON.parse request.body.read
|
40
|
+
response_map[request_body["action"]].to_json
|
41
|
+
end
|
42
|
+
|
43
|
+
post '/deny/action.php' do
|
44
|
+
request_body = JSON.parse request.body.read
|
45
|
+
response = response_map[request_body["action"]].clone
|
46
|
+
response["status"] = -1
|
47
|
+
response.to_json
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: LYBC
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marios Antonoudiou
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-25 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 9.0.5
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 9.0.5
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.4.7
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.4.7
|
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.2
|
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.2
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- marios@artime.gr
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- .travis.yml
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- LYBC.gemspec
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/mock_server
|
114
|
+
- bin/setup
|
115
|
+
- lib/LYBC.rb
|
116
|
+
- lib/LYBC/client.rb
|
117
|
+
- lib/LYBC/version.rb
|
118
|
+
- mock_server.rb
|
119
|
+
homepage: https://github.com/artime-advertising/LYBC-ruby
|
120
|
+
licenses: []
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.4.8
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Ruby client for LYBC Greece
|
142
|
+
test_files: []
|