goldshark_gem 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +49 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +23 -0
- data/LICENSE.txt +20 -0
- data/README +118 -0
- data/README.rdoc +118 -0
- data/Rakefile +21 -0
- data/goldshark_gem.gemspec +11 -0
- data/lib/goldshark_gem.rb +247 -0
- data/test/goldshark_gem_test.rb +25 -0
- data/test/helper.rb +12 -0
- data/test/vcr_setup.rb +6 -0
- data/vcr_cassettes/.DS_Store +0 -0
- data/vcr_cassettes/test_tool.yml +68 -0
- metadata +60 -0
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
coverage.data
|
4
|
+
|
5
|
+
# rdoc generated
|
6
|
+
rdoc
|
7
|
+
|
8
|
+
# yard generated
|
9
|
+
doc
|
10
|
+
.yardoc
|
11
|
+
|
12
|
+
# bundler
|
13
|
+
.bundle
|
14
|
+
|
15
|
+
# jeweler generated
|
16
|
+
pkg
|
17
|
+
|
18
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
19
|
+
#
|
20
|
+
# * Create a file at ~/.gitignore
|
21
|
+
# * Include files you want ignored
|
22
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
23
|
+
#
|
24
|
+
# After doing this, these files will be ignored in all your git projects,
|
25
|
+
# saving you from having to 'pollute' every project you touch with them
|
26
|
+
#
|
27
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
28
|
+
#
|
29
|
+
# For MacOS:
|
30
|
+
#
|
31
|
+
#.DS_Store
|
32
|
+
|
33
|
+
# For TextMate
|
34
|
+
#*.tmproj
|
35
|
+
#tmtags
|
36
|
+
|
37
|
+
# For emacs:
|
38
|
+
#*~
|
39
|
+
#\#*
|
40
|
+
#.\#*
|
41
|
+
|
42
|
+
# For vim:
|
43
|
+
#*.swp
|
44
|
+
|
45
|
+
# For redcar:
|
46
|
+
#.redcar
|
47
|
+
|
48
|
+
# For rubinius:
|
49
|
+
#*.rbc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://gemcutter.org/
|
3
|
+
specs:
|
4
|
+
ZenTest (4.8.2)
|
5
|
+
ansi (1.4.3)
|
6
|
+
fakeweb (1.3.0)
|
7
|
+
minitest (3.4.0)
|
8
|
+
rake (0.9.2.2)
|
9
|
+
turn (0.9.6)
|
10
|
+
ansi
|
11
|
+
vcr (2.2.5)
|
12
|
+
|
13
|
+
PLATFORMS
|
14
|
+
ruby
|
15
|
+
|
16
|
+
DEPENDENCIES
|
17
|
+
ZenTest
|
18
|
+
bundler
|
19
|
+
fakeweb
|
20
|
+
minitest
|
21
|
+
rake
|
22
|
+
turn
|
23
|
+
vcr
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Gabriele Roselli
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
= goldshark_gem
|
2
|
+
|
3
|
+
Initialization:
|
4
|
+
|
5
|
+
gs = GS::Tool.new(localization)
|
6
|
+
texts = GS::Text.new(localization)
|
7
|
+
|
8
|
+
localization is the parameter key you will need to define in the YAML file. The config file has to be named 'tool_config.yml' and placed in the config folder of the Rails app.
|
9
|
+
|
10
|
+
localization = 'en_us' or 'fridge_finder' or whatever you want it to be
|
11
|
+
|
12
|
+
YAML file Sample (tool_config.yml)
|
13
|
+
|
14
|
+
en_us:
|
15
|
+
tool_guid: '12343252'
|
16
|
+
locale: 'en'
|
17
|
+
api_root: 'http://gst.api.igodigital.com/v2_2' # this option is optional it gsaults to v2_2
|
18
|
+
|
19
|
+
fridge_finder:
|
20
|
+
tool_guid: '3255423'
|
21
|
+
locale: 'en'
|
22
|
+
api_root: 'http://gst.api.igodigital.com/v2_2' # this option is optional it gsaults to v2_2
|
23
|
+
|
24
|
+
|
25
|
+
If the tool_config.yml file is missing or you are not developing in the Rails enveironment. An empty object can be created and the variables can be defined like so:
|
26
|
+
|
27
|
+
gs = GS::Tool.new
|
28
|
+
|
29
|
+
gs.tool_guid('132424324')
|
30
|
+
gs.session_id('92034802')
|
31
|
+
gs.locale('en')
|
32
|
+
gs.url('http://gst.api.igodigital.com/v2_2')
|
33
|
+
|
34
|
+
texts = GS::Text.new
|
35
|
+
|
36
|
+
texts.tool_guid('132424324')
|
37
|
+
texts.locale('en')
|
38
|
+
|
39
|
+
To retrieve the 'gs' object variables just call:
|
40
|
+
|
41
|
+
gs.tool_guid or texts.tool_guid
|
42
|
+
=> '1233242'
|
43
|
+
|
44
|
+
gs.session_id
|
45
|
+
=> '322342'
|
46
|
+
|
47
|
+
gs.locale or texts.locale
|
48
|
+
=> 'en'
|
49
|
+
|
50
|
+
gs.url
|
51
|
+
=> 'http://gst.api.igodigital.com/v2_2'
|
52
|
+
|
53
|
+
|
54
|
+
All calls return hashes with symbolized keys and all product calls return a constant structure for the product object:
|
55
|
+
|
56
|
+
Load and Search a text. After the text object is initialized. The find method returns the value as a string. (The text type is always defined unlike the text name so I picked that param to make the call).
|
57
|
+
|
58
|
+
texts.load_texts
|
59
|
+
|
60
|
+
text.find(text_type)
|
61
|
+
|
62
|
+
Example:
|
63
|
+
|
64
|
+
text.find('buy_now')
|
65
|
+
=> 'Buy Now'
|
66
|
+
|
67
|
+
Grab the tool object with session id if defined, without session id if not defined.
|
68
|
+
|
69
|
+
gs.get_tool
|
70
|
+
|
71
|
+
This call accepts an array of tool step option ids and returns the results tool object.
|
72
|
+
|
73
|
+
gs.get_results(tool_step_option_ids)
|
74
|
+
|
75
|
+
This call accepts one skus or a string of comma separated values of skus and returns a products array.
|
76
|
+
|
77
|
+
gs.get_products_by_skus(skus)
|
78
|
+
|
79
|
+
This call accepts one retailer_product_id or a string of comma separated values of retailer_product_ids and returns a products array.
|
80
|
+
|
81
|
+
gs.get_products_by_product_ids(product_ids)
|
82
|
+
|
83
|
+
This call accepts an attribute name and returns an array of the requested attribute for all products.
|
84
|
+
|
85
|
+
gs.get_attribute_by_name(attribute_name)
|
86
|
+
|
87
|
+
This call will return all products linked to the retailer_product_id listed.
|
88
|
+
|
89
|
+
gs.get_product_links(retailer_product_id)
|
90
|
+
|
91
|
+
This call will return the user data of the gs.session_id. The user_id param is optional.
|
92
|
+
|
93
|
+
gs.get_user_data(user_id)
|
94
|
+
|
95
|
+
This call accepts session_data (it can be anything you want to save). And it save it to the user data.
|
96
|
+
|
97
|
+
gs.save_user_data(session_data, user_id)
|
98
|
+
|
99
|
+
This call records recommendation based on the gs.session_id. You will need to pass the group id and the retailer product list (not optional).
|
100
|
+
|
101
|
+
gs.recs(group_id, retailer_product_list)
|
102
|
+
|
103
|
+
This call will record the event passed on the gs.session_id.
|
104
|
+
|
105
|
+
gs.record_events(event_name)
|
106
|
+
|
107
|
+
This call will record microconversion based on the gs.session_id and the retailer product id passed (param not optional).
|
108
|
+
gs.micro_convert(retailer_product_id)
|
109
|
+
|
110
|
+
== Contributing to goldshark_gem
|
111
|
+
|
112
|
+
Gabriele Roselli
|
113
|
+
|
114
|
+
== Copyright
|
115
|
+
|
116
|
+
Copyright (c) 2012 iGoDigital. See LICENSE.txt for
|
117
|
+
further details.
|
118
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
= goldshark_gem
|
2
|
+
|
3
|
+
Initialization:
|
4
|
+
|
5
|
+
gs = GS::Tool.new(localization)
|
6
|
+
texts = GS::Text.new(localization)
|
7
|
+
|
8
|
+
localization is the parameter key you will need to define in the YAML file. The config file has to be named 'tool_config.yml' and placed in the config folder of the Rails app.
|
9
|
+
|
10
|
+
localization = 'en_us' or 'fridge_finder' or whatever you want it to be
|
11
|
+
|
12
|
+
YAML file Sample (tool_config.yml)
|
13
|
+
|
14
|
+
en_us:
|
15
|
+
tool_guid: '12343252'
|
16
|
+
locale: 'en'
|
17
|
+
api_root: 'http://gst.api.igodigital.com/v2_2' # this option is optional it gsaults to v2_2
|
18
|
+
|
19
|
+
fridge_finder:
|
20
|
+
tool_guid: '3255423'
|
21
|
+
locale: 'en'
|
22
|
+
api_root: 'http://gst.api.igodigital.com/v2_2' # this option is optional it gsaults to v2_2
|
23
|
+
|
24
|
+
|
25
|
+
If the tool_config.yml file is missing or you are not developing in the Rails enveironment. An empty object can be created and the variables can be defined like so:
|
26
|
+
|
27
|
+
gs = GS::Tool.new
|
28
|
+
|
29
|
+
gs.tool_guid('132424324')
|
30
|
+
gs.session_id('92034802')
|
31
|
+
gs.locale('en')
|
32
|
+
gs.url('http://gst.api.igodigital.com/v2_2')
|
33
|
+
|
34
|
+
texts = GS::Text.new
|
35
|
+
|
36
|
+
texts.tool_guid('132424324')
|
37
|
+
texts.locale('en')
|
38
|
+
|
39
|
+
To retrieve the 'gs' object variables just call:
|
40
|
+
|
41
|
+
gs.tool_guid or texts.tool_guid
|
42
|
+
=> '1233242'
|
43
|
+
|
44
|
+
gs.session_id
|
45
|
+
=> '322342'
|
46
|
+
|
47
|
+
gs.locale or texts.locale
|
48
|
+
=> 'en'
|
49
|
+
|
50
|
+
gs.url
|
51
|
+
=> 'http://gst.api.igodigital.com/v2_2'
|
52
|
+
|
53
|
+
|
54
|
+
All calls return hashes with symbolized keys and all product calls return a constant structure for the product object:
|
55
|
+
|
56
|
+
Load and Search a text. After the text object is initialized. The find method returns the value as a string. (The text type is always defined unlike the text name so I picked that param to make the call).
|
57
|
+
|
58
|
+
texts.load_texts
|
59
|
+
|
60
|
+
text.find(text_type)
|
61
|
+
|
62
|
+
Example:
|
63
|
+
|
64
|
+
text.find('buy_now')
|
65
|
+
=> 'Buy Now'
|
66
|
+
|
67
|
+
Grab the tool object with session id if defined, without session id if not defined.
|
68
|
+
|
69
|
+
gs.get_tool
|
70
|
+
|
71
|
+
This call accepts an array of tool step option ids and returns the results tool object.
|
72
|
+
|
73
|
+
gs.get_results(tool_step_option_ids)
|
74
|
+
|
75
|
+
This call accepts one skus or a string of comma separated values of skus and returns a products array.
|
76
|
+
|
77
|
+
gs.get_products_by_skus(skus)
|
78
|
+
|
79
|
+
This call accepts one retailer_product_id or a string of comma separated values of retailer_product_ids and returns a products array.
|
80
|
+
|
81
|
+
gs.get_products_by_product_ids(product_ids)
|
82
|
+
|
83
|
+
This call accepts an attribute name and returns an array of the requested attribute for all products.
|
84
|
+
|
85
|
+
gs.get_attribute_by_name(attribute_name)
|
86
|
+
|
87
|
+
This call will return all products linked to the retailer_product_id listed.
|
88
|
+
|
89
|
+
gs.get_product_links(retailer_product_id)
|
90
|
+
|
91
|
+
This call will return the user data of the gs.session_id. The user_id param is optional.
|
92
|
+
|
93
|
+
gs.get_user_data(user_id)
|
94
|
+
|
95
|
+
This call accepts session_data (it can be anything you want to save). And it save it to the user data.
|
96
|
+
|
97
|
+
gs.save_user_data(session_data, user_id)
|
98
|
+
|
99
|
+
This call records recommendation based on the gs.session_id. You will need to pass the group id and the retailer product list (not optional).
|
100
|
+
|
101
|
+
gs.recs(group_id, retailer_product_list)
|
102
|
+
|
103
|
+
This call will record the event passed on the gs.session_id.
|
104
|
+
|
105
|
+
gs.record_events(event_name)
|
106
|
+
|
107
|
+
This call will record microconversion based on the gs.session_id and the retailer product id passed (param not optional).
|
108
|
+
gs.micro_convert(retailer_product_id)
|
109
|
+
|
110
|
+
== Contributing to goldshark_gem
|
111
|
+
|
112
|
+
Gabriele Roselli
|
113
|
+
|
114
|
+
== Copyright
|
115
|
+
|
116
|
+
Copyright (c) 2012 iGoDigital. See LICENSE.txt for
|
117
|
+
further details.
|
118
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
|
6
|
+
begin
|
7
|
+
Bundler.setup(:default, :test)
|
8
|
+
rescue Bundler::BundlerError => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
11
|
+
exit e.status_code
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rake'
|
15
|
+
require 'rake/testtask'
|
16
|
+
|
17
|
+
Rake::TestTask.new do |test|
|
18
|
+
test.libs << 'lib' << 'test'
|
19
|
+
test.pattern = 'test/*_test.rb'
|
20
|
+
test.verbose = true
|
21
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.name = "goldshark_gem"
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.authors = ["Gabriele Roselli"]
|
6
|
+
s.email = ["groselli@igodigital.com"]
|
7
|
+
s.summary = %q{A gem to interact with iGodigital GoldShark API}
|
8
|
+
s.description = %q{A gem to interact with iGodigital GoldShark API}
|
9
|
+
s.files = `git ls-files`.split($\)
|
10
|
+
s.version = '0.1.0'
|
11
|
+
end
|
@@ -0,0 +1,247 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'uri'
|
4
|
+
require 'JSON'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
module GS
|
8
|
+
class Tool
|
9
|
+
def initialize(localization = nil)
|
10
|
+
unless localization.nil?
|
11
|
+
config_file = Rails.root.join("config", "tool_config.yml").to_s
|
12
|
+
tool_info = YAML::load(File.read(config_file))
|
13
|
+
@tool_guid = tool_info[localization]['tool_guid']
|
14
|
+
@locale = tool_info[localization]['locale']
|
15
|
+
end
|
16
|
+
@url = tool_info['api_root'] rescue nil
|
17
|
+
if @url.nil?
|
18
|
+
@url = 'http://gst.api.igodigital.com/v2_2'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def session_id(sid = nil)
|
23
|
+
if sid.nil?
|
24
|
+
@session_id
|
25
|
+
else
|
26
|
+
@session_id = sid
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def tool_guid(tool_guid = nil)
|
31
|
+
if tool_guid.nil?
|
32
|
+
@tool_guid
|
33
|
+
else
|
34
|
+
@tool_guid = tool_guid
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def locale(locale = nil)
|
39
|
+
if locale.nil?
|
40
|
+
@locale
|
41
|
+
else
|
42
|
+
@locale = locale
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def url(url = nil)
|
47
|
+
if url.nil?
|
48
|
+
@url
|
49
|
+
else
|
50
|
+
@url = url
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_tool
|
55
|
+
unless @session_id.nil?
|
56
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/tool.json?locale=#{@locale}&sid=#{@session_id}")
|
57
|
+
else
|
58
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/tool.json?locale=#{@locale}")
|
59
|
+
end
|
60
|
+
return get_call(uri)
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_settings(setting_name = nil)
|
64
|
+
if setting_name.nil?
|
65
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/settings.json")
|
66
|
+
else
|
67
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/settings.json?name=#{setting_name}")
|
68
|
+
end
|
69
|
+
return get_call(uri)
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_results(tool_step_option_ids = nil, completed = "true")
|
73
|
+
tool = get_tool
|
74
|
+
unless tool_step_option_ids.nil?
|
75
|
+
tool[:steps] = update_tool_options(tool, tool_step_option_ids)
|
76
|
+
end
|
77
|
+
tool[:steps].each{|step| step.reject!{|key, value| ![:tool_step_id, :selected_options, :selected_filter_options].include?(key)}}
|
78
|
+
if @session_id.nil?
|
79
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/tool.json?locale=#{@locale}&sid=#{@session_id}&completed=#{completed}")
|
80
|
+
else
|
81
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/tool.json?locale=#{@locale}&completed=#{completed}")
|
82
|
+
end
|
83
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
84
|
+
request = Net::HTTP::Put.new(uri.request_uri)
|
85
|
+
request.body = tool.to_json
|
86
|
+
response = http.request(request)
|
87
|
+
return JSON.parse(response.body, {symbolize_names: true})
|
88
|
+
end
|
89
|
+
|
90
|
+
def get_products_by_skus(skus)
|
91
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/products.json?sku_list=#{skus}")
|
92
|
+
products = get_call(uri)
|
93
|
+
return products.collect{|p| p[:product]}
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_products_by_product_ids(product_ids)
|
97
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/products.json?product_list=#{product_ids}")
|
98
|
+
products = get_call(uri)
|
99
|
+
return products.collect{|p| p[:product]}
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_attribute_by_name(attribute_name)
|
103
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/product_attributes.json?attribute_name=#{attribute_name}")
|
104
|
+
return get_call(uri)
|
105
|
+
end
|
106
|
+
|
107
|
+
def get_product_links(retailer_product_id)
|
108
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/product_links/#{retailer_product_id}.json")
|
109
|
+
return get_call(uri)
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_user_data(user_id = nil)
|
113
|
+
if !@session_id.nil? && !user_id.nil?
|
114
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/user_data.json?sid=#{@session_id}&user_id=#{user_id}")
|
115
|
+
response = get_call(uri)
|
116
|
+
elsif @session_id.nil? && !user_id.nil?
|
117
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/user_data.json?user_id=#{user_id}")
|
118
|
+
response = get_call(uri).last
|
119
|
+
elsif !@session_id.nil? && user_id.nil?
|
120
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/user_data.json?sid=#{@session_id}")
|
121
|
+
response = get_call(uri)
|
122
|
+
end
|
123
|
+
return response
|
124
|
+
end
|
125
|
+
|
126
|
+
def save_user_data(session_data, user_id = nil)
|
127
|
+
unless session_data.empty?
|
128
|
+
if user_id.nil?
|
129
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/user_data.json?sid=#{@session_id}")
|
130
|
+
else
|
131
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/user_data.json?sid=#{@session_id}&user_id=#{user_id}")
|
132
|
+
end
|
133
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
134
|
+
request = Net::HTTP::Put.new(uri.request_uri)
|
135
|
+
request.body = session_data.to_json
|
136
|
+
response = http.request(request)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def recs(group_id, retailer_product_list)
|
141
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/recommend.json?group_id=#{group_id}&retailer_product_list=#{retailer_product_list}")
|
142
|
+
return get_call(uri)
|
143
|
+
end
|
144
|
+
|
145
|
+
def record_events(event_name)
|
146
|
+
if @session_id.nil?
|
147
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/record_event/#{event_name}.json")
|
148
|
+
else
|
149
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/record_event/#{event_name}.json?sid=#{@session_id}")
|
150
|
+
end
|
151
|
+
return get_call(uri)
|
152
|
+
end
|
153
|
+
|
154
|
+
def micro_convert(retailer_product_id)
|
155
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/micro_conversions.json?sid=#{@session_id}&retailer_product_id=#{retailer_product_id}")
|
156
|
+
return get_call(uri)
|
157
|
+
end
|
158
|
+
|
159
|
+
def get_call(uri)
|
160
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
161
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
162
|
+
response = http.request(request)
|
163
|
+
return JSON.parse(response.body, {symbolize_names: true})
|
164
|
+
end
|
165
|
+
|
166
|
+
def update_tool_options(tool, tool_step_option_ids)
|
167
|
+
tool[:steps].each do |step|
|
168
|
+
current_step_options = []
|
169
|
+
unless step[:options].nil?
|
170
|
+
step[:options].each do |option|
|
171
|
+
if Array(tool_step_option_ids).include?(option[:tool_step_option_id])
|
172
|
+
current_step_options << option[:tool_step_option_id]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
unless current_step_options.empty?
|
177
|
+
step[:selected_options] = current_step_options.join(',')
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
class Text
|
184
|
+
def initialize(localization = nil)
|
185
|
+
unless localization.nil?
|
186
|
+
config_file = Rails.root.join("config", "tool_config.yml").to_s
|
187
|
+
tool_info = YAML::load(File.read(config_file))
|
188
|
+
@tool_guid = tool_info[localization]['tool_guid']
|
189
|
+
@locale = tool_info[localization]['locale']
|
190
|
+
end
|
191
|
+
@url = tool_info['api_root'] rescue nil
|
192
|
+
if @url.nil?
|
193
|
+
@url = 'http://gst.api.igodigital.com/v2_2'
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def locale(locale = nil)
|
198
|
+
if locale.nil?
|
199
|
+
@locale
|
200
|
+
else
|
201
|
+
@locale = locale
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def tool_guid(tool_guid = nil)
|
206
|
+
if tool_guid.nil?
|
207
|
+
@tool_guid
|
208
|
+
else
|
209
|
+
@tool_guid = tool_guid
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
def url(url = nil)
|
214
|
+
if url.nil?
|
215
|
+
@url
|
216
|
+
else
|
217
|
+
@url = url
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def texts(texts = [])
|
222
|
+
if texts.empty?
|
223
|
+
@texts
|
224
|
+
else
|
225
|
+
@texts = texts
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def load_text
|
230
|
+
uri = URI.parse("#{@url}/#{@tool_guid}/text.json?locale=#{@locale}")
|
231
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
232
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
233
|
+
response = http.request(request)
|
234
|
+
@texts = JSON.parse(response.body, {symbolize_names: true})
|
235
|
+
return @texts
|
236
|
+
end
|
237
|
+
|
238
|
+
def find(param)
|
239
|
+
@texts.each do |x|
|
240
|
+
if x[:text_type] == param
|
241
|
+
return x[:text_value]
|
242
|
+
end
|
243
|
+
end
|
244
|
+
return nil
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
class TestGoldsharkGem < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@gs = GS::Tool.new
|
8
|
+
@gs.tool_guid('7c7a63f6-8bcb-4fee-bc9d-8a2f5e477887')
|
9
|
+
@gs.locale('en')
|
10
|
+
|
11
|
+
@gstxt = GS::Text.new
|
12
|
+
@gstxt.tool_guid("7c7a63f6-8bcb-4fee-bc9d-8a2f5e477887")
|
13
|
+
@gstxt.locale("en")
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'test_use_vcr' do
|
18
|
+
VCR.use_cassette('test_tool') do
|
19
|
+
@gs.session_id('7c7a63f6-8bcb-4fee-bc9d-8a2f5e477887')
|
20
|
+
@tool = @gs.get_tool
|
21
|
+
assert_equal '7c7a63f6-8bcb-4fee-bc9d-8a2f5e477887', @tool[:session_id]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'vcr_setup'
|
3
|
+
Bundler.require(:default, :test)
|
4
|
+
require 'goldshark_gem'
|
5
|
+
require 'minitest/unit'
|
6
|
+
require 'turn'
|
7
|
+
|
8
|
+
class MiniTest::Unit::TestCase
|
9
|
+
def self.test(name, &block)
|
10
|
+
define_method name + '_test.rb', &block
|
11
|
+
end
|
12
|
+
end
|
data/test/vcr_setup.rb
ADDED
Binary file
|
@@ -0,0 +1,68 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://gst.api.igodigital.com/v2_2/7c7a63f6-8bcb-4fee-bc9d-8a2f5e477887/tool.json?locale=en&sid=7c7a63f6-8bcb-4fee-bc9d-8a2f5e477887
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
accept:
|
11
|
+
- ! '*/*'
|
12
|
+
user-agent:
|
13
|
+
- Ruby
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
content-type:
|
20
|
+
- application/json;charset=utf-8
|
21
|
+
date:
|
22
|
+
- Fri, 14 Sep 2012 15:30:07 GMT
|
23
|
+
server:
|
24
|
+
- Apache/2.2.16 (Amazon)
|
25
|
+
status:
|
26
|
+
- '200'
|
27
|
+
x-frame-options:
|
28
|
+
- sameorigin
|
29
|
+
x-powered-by:
|
30
|
+
- Phusion Passenger (mod_rails/mod_rack) 3.0.9
|
31
|
+
x-xss-protection:
|
32
|
+
- 1; mode=block
|
33
|
+
content-length:
|
34
|
+
- '4495'
|
35
|
+
connection:
|
36
|
+
- Close
|
37
|
+
body:
|
38
|
+
encoding: US-ASCII
|
39
|
+
string: ! '{"tool_name":"This tool is used for monitoring only --- Philips -
|
40
|
+
Shaver Head Finder","session_id":"7c7a63f6-8bcb-4fee-bc9d-8a2f5e477887","steps":[{"parent_tool_step_id":"0","parent_tool_step_option_id":"0","required":"
|
41
|
+
","sort_order":0,"question_type":"","step_header":"Every year, your blades
|
42
|
+
travel the height of Mt. Everest... 49 times! After such a workout, even the
|
43
|
+
best materials can lose their edge. Retain your razor''s peak performance
|
44
|
+
- replace the heads once a year.","step_name":"Welcome Page","step_title":"Keep
|
45
|
+
a close shave","step_type_name":"Welcome / Info","tool_step_id":"2fdde68c-43e1-4cad-9fdc-cf770fe1dede","selected_options":"","selected_filter_options":null,"image_type":"","":[]},{"parent_tool_step_id":"0","parent_tool_step_option_id":"0","required":"
|
46
|
+
","sort_order":1,"question_type":"radio","step_header":"","step_name":"Shaving
|
47
|
+
Heads","step_title":"How many shaving heads does your shaver have?","step_type_name":"Step
|
48
|
+
Listing (Parent)","tool_step_id":"484282c3-e919-4a07-be83-cc36582491f9","selected_options":"","selected_filter_options":null,"image_type":"jpg","options":[{"parent_step_option_name":"","parent_tool_step_option_id":"0","sort_order":0,"step_option_desc":"","step_option_name":"It
|
49
|
+
has three shaving heads.","step_option_notes":"","tool_step_option_id":"0e1ba264-7ed2-4a85-b9cb-75aa50b2b43c","image_type":"jpg"},{"parent_step_option_name":"","parent_tool_step_option_id":"0","sort_order":1,"step_option_desc":"HQ56/52","step_option_name":"It
|
50
|
+
has two shaving heads.","step_option_notes":"","tool_step_option_id":"876f39dc-3275-4ba5-a0a1-417bfb974fb0","image_type":"jpg"}]},{"parent_tool_step_id":"0","parent_tool_step_option_id":"0","required":"
|
51
|
+
","sort_order":2,"question_type":"radio","step_header":"","step_name":"Nivea
|
52
|
+
Shaver","step_title":"Do You Have a Nivea Shaver?","step_type_name":"Step
|
53
|
+
Listing (Parent)","tool_step_id":"ac5c824d-270f-4581-a4e9-49070fac8650","selected_options":"","selected_filter_options":null,"image_type":"","options":[{"parent_step_option_name":"","parent_tool_step_option_id":"0","sort_order":0,"step_option_desc":"","step_option_name":"I
|
54
|
+
have a Nivea shaver","step_option_notes":"","tool_step_option_id":"1c3d1d63-556d-482d-aaf0-8b3700deb29b","image_type":"jpg"},{"parent_step_option_name":"","parent_tool_step_option_id":"0","sort_order":1,"step_option_desc":"","step_option_name":"I
|
55
|
+
have a different shaver","step_option_notes":"no-image","tool_step_option_id":"31786a9a-be79-422c-b551-ff7d20e62112","image_type":"jpg"}]},{"parent_tool_step_id":"0","parent_tool_step_option_id":"0","required":"
|
56
|
+
","sort_order":3,"question_type":"radio","step_header":"","step_name":"Neck","step_title":"Does
|
57
|
+
your shaver have a ''neck''?","step_type_name":"Step Listing (Parent)","tool_step_id":"ef5f71cd-04d4-42d3-ba93-51282ee82e19","selected_options":"","selected_filter_options":null,"image_type":"","options":[{"parent_step_option_name":"","parent_tool_step_option_id":"0","sort_order":0,"step_option_desc":"","step_option_name":"Yes,
|
58
|
+
the shaving head is on a ''neck''","step_option_notes":"","tool_step_option_id":"0031fade-61db-458d-a189-cad2db67427e","image_type":"jpg"},{"parent_step_option_name":"","parent_tool_step_option_id":"0","sort_order":1,"step_option_desc":"","step_option_name":"No,
|
59
|
+
the shaving head is integrated","step_option_notes":"","tool_step_option_id":"6a95ca9d-e343-4061-a161-7057d9d0e208","image_type":"jpg"}]},{"parent_tool_step_id":"ef5f71cd-04d4-42d3-ba93-51282ee82e19","parent_tool_step_option_id":"0","required":"
|
60
|
+
","sort_order":1000,"question_type":"radio","step_header":"","step_name":"Plastic
|
61
|
+
Color","step_title":"Is the color of the plastic at the back side green? ","step_type_name":"Popup","tool_step_id":"7f8986a5-2e78-4c18-8934-71d37551a462","selected_options":"","selected_filter_options":null,"image_type":"","options":[{"parent_step_option_name":"Yes,
|
62
|
+
the shaving head is on a ''neck''","parent_tool_step_option_id":"0031fade-61db-458d-a189-cad2db67427e","sort_order":0,"step_option_desc":"HQ8/52","step_option_name":"Yes,
|
63
|
+
the back side is green","step_option_notes":"","tool_step_option_id":"419ff79f-14a9-4702-bb05-269b7461e2b4","image_type":"jpg"},{"parent_step_option_name":"Yes,
|
64
|
+
the shaving head is on a ''neck''","parent_tool_step_option_id":"0031fade-61db-458d-a189-cad2db67427e","sort_order":1,"step_option_desc":"HQ56/52
|
65
|
+
","step_option_name":"No, the back side is not green","step_option_notes":"no-image","tool_step_option_id":"29bf4cd7-1504-443f-8541-fee1fe73c921","image_type":"jpg"}]}]}'
|
66
|
+
http_version: '1.1'
|
67
|
+
recorded_at: Fri, 14 Sep 2012 15:30:06 GMT
|
68
|
+
recorded_with: VCR 2.2.5
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: goldshark_gem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gabriele Roselli
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-14 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A gem to interact with iGodigital GoldShark API
|
15
|
+
email:
|
16
|
+
- groselli@igodigital.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .document
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE.txt
|
26
|
+
- README
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- goldshark_gem.gemspec
|
30
|
+
- lib/goldshark_gem.rb
|
31
|
+
- test/goldshark_gem_test.rb
|
32
|
+
- test/helper.rb
|
33
|
+
- test/vcr_setup.rb
|
34
|
+
- vcr_cassettes/.DS_Store
|
35
|
+
- vcr_cassettes/test_tool.yml
|
36
|
+
homepage:
|
37
|
+
licenses: []
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.8.24
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: A gem to interact with iGodigital GoldShark API
|
60
|
+
test_files: []
|