goldshark_gem 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -3
- data/Gemfile.lock +14 -2
- data/README.md +162 -0
- data/goldshark_gem.gemspec +7 -1
- data/lib/goldshark_gem.rb +5 -241
- data/lib/goldshark_gem/ci.rb +38 -0
- data/lib/goldshark_gem/text.rb +67 -0
- data/lib/goldshark_gem/tool.rb +176 -0
- data/test/ci_test.rb +19 -0
- data/test/fixtures/vcr_cassettes/test_channel_intelligence.yml +49 -0
- data/test/fixtures/vcr_cassettes/test_results.yml +687 -0
- data/test/fixtures/vcr_cassettes/test_text.yml +67 -0
- data/{vcr_cassettes → test/fixtures/vcr_cassettes}/test_tool.yml +16 -16
- data/test/helper.rb +1 -0
- data/test/text_test.rb +18 -0
- data/test/tool_test.rb +40 -0
- data/test/vcr_setup.rb +2 -2
- metadata +48 -9
- data/README +0 -124
- data/README.rdoc +0 -124
- data/test/goldshark_gem_test.rb +0 -25
- data/vcr_cassettes/.DS_Store +0 -0
data/Gemfile
CHANGED
@@ -2,11 +2,12 @@ source 'http://gemcutter.org'
|
|
2
2
|
|
3
3
|
gem 'bundler'
|
4
4
|
gem 'rake'
|
5
|
-
|
5
|
+
gem "activesupport", "3.2.8", :require => "active_support"
|
6
|
+
gem 'libxml-ruby'
|
6
7
|
group :test do
|
7
8
|
gem 'minitest'
|
8
9
|
gem 'ZenTest'
|
9
|
-
|
10
|
+
gem 'webmock'
|
11
|
+
gem 'turn'
|
10
12
|
gem 'vcr'
|
11
|
-
gem 'fakeweb'
|
12
13
|
end
|
data/Gemfile.lock
CHANGED
@@ -2,22 +2,34 @@ GEM
|
|
2
2
|
remote: http://gemcutter.org/
|
3
3
|
specs:
|
4
4
|
ZenTest (4.8.2)
|
5
|
+
activesupport (3.2.8)
|
6
|
+
i18n (~> 0.6)
|
7
|
+
multi_json (~> 1.0)
|
8
|
+
addressable (2.3.2)
|
5
9
|
ansi (1.4.3)
|
6
|
-
|
10
|
+
crack (0.3.1)
|
11
|
+
i18n (0.6.1)
|
12
|
+
libxml-ruby (2.3.3)
|
7
13
|
minitest (3.4.0)
|
14
|
+
multi_json (1.3.6)
|
8
15
|
rake (0.9.2.2)
|
9
16
|
turn (0.9.6)
|
10
17
|
ansi
|
11
18
|
vcr (2.2.5)
|
19
|
+
webmock (1.8.11)
|
20
|
+
addressable (>= 2.2.7)
|
21
|
+
crack (>= 0.1.7)
|
12
22
|
|
13
23
|
PLATFORMS
|
14
24
|
ruby
|
15
25
|
|
16
26
|
DEPENDENCIES
|
17
27
|
ZenTest
|
28
|
+
activesupport (= 3.2.8)
|
18
29
|
bundler
|
19
|
-
|
30
|
+
libxml-ruby
|
20
31
|
minitest
|
21
32
|
rake
|
22
33
|
turn
|
23
34
|
vcr
|
35
|
+
webmock
|
data/README.md
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
Goldshark Gem
|
2
|
+
===
|
3
|
+
---
|
4
|
+
To Install
|
5
|
+
---
|
6
|
+
|
7
|
+
gem install goldshark\_gem
|
8
|
+
|
9
|
+
###Put in Rails Gemfile
|
10
|
+
|
11
|
+
gem 'goldshark_gem'
|
12
|
+
|
13
|
+
###Usage
|
14
|
+
|
15
|
+
gs = GS::Tool.new(localization)
|
16
|
+
texts = GS::Text.new(localization)
|
17
|
+
|
18
|
+
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.
|
19
|
+
|
20
|
+
**localization = 'en\_us' or 'fridge\_finder' or whatever you want it to be.**
|
21
|
+
|
22
|
+
###YAML file Sample (tool\_config.yml)
|
23
|
+
|
24
|
+
en_us:
|
25
|
+
tool_guid: '12343252'
|
26
|
+
locale: 'en'
|
27
|
+
api_root: 'http://gst.api.igodigital.com/v2_2' # this option is optional it gsaults to v2_2
|
28
|
+
|
29
|
+
fridge_finder:
|
30
|
+
tool_guid: '3255423'
|
31
|
+
locale: 'en'
|
32
|
+
api_root: 'http://gst.api.igodigital.com/v2_2' # this option is optional it gsaults to v2_2
|
33
|
+
|
34
|
+
###Without YAML config file
|
35
|
+
|
36
|
+
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:
|
37
|
+
|
38
|
+
gs = GS::Tool.new
|
39
|
+
gs.tool_guid('132424324')
|
40
|
+
gs.session_id('92034802')
|
41
|
+
gs.locale('en')
|
42
|
+
gs.url('http://gst.api.igodigital.com/v2_2')
|
43
|
+
|
44
|
+
texts = GS::Text.new
|
45
|
+
texts.tool_guid('132424324')
|
46
|
+
texts.locale('en')
|
47
|
+
|
48
|
+
###Retrieve the 'gs' object variables
|
49
|
+
|
50
|
+
gs.tool_guid or texts.tool_guid
|
51
|
+
=> '1233242'
|
52
|
+
|
53
|
+
gs.session_id
|
54
|
+
=> '322342'
|
55
|
+
|
56
|
+
gs.locale or texts.locale
|
57
|
+
=> 'en'
|
58
|
+
|
59
|
+
gs.url
|
60
|
+
=> 'http://gst.api.igodigital.com/v2_2'
|
61
|
+
|
62
|
+
|
63
|
+
**All calls return hashes with symbolized keys and all product calls return a constant structure for the product object**
|
64
|
+
|
65
|
+
###Load and Search a text
|
66
|
+
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).
|
67
|
+
|
68
|
+
texts.load_texts
|
69
|
+
|
70
|
+
text.find(text_type)
|
71
|
+
|
72
|
+
###Example:
|
73
|
+
|
74
|
+
text.find('buy_now')
|
75
|
+
=> 'Buy Now'
|
76
|
+
|
77
|
+
###Grab the tool object with session id if defined, without session id if not defined
|
78
|
+
|
79
|
+
gs.get_tool
|
80
|
+
|
81
|
+
The following accepts an **array of tool step option ids** and returns the results tool object.
|
82
|
+
|
83
|
+
gs.get_results(tool_step_option_ids)
|
84
|
+
|
85
|
+
###Get Products by skus or product ids
|
86
|
+
|
87
|
+
The following call accepts one skus or a string of comma separated values of skus and returns a products array.
|
88
|
+
|
89
|
+
gs.get_products_by_skus(skus)
|
90
|
+
|
91
|
+
The following call accepts one retailer\_product\_id or a string of comma separated values of retailer\_product\_ids and returns a products array.
|
92
|
+
|
93
|
+
gs.get_products_by_product_ids(product_ids)
|
94
|
+
|
95
|
+
###Get Attributes and Product links
|
96
|
+
The following call accepts an attribute name and returns an array of the requested attribute for all products.
|
97
|
+
|
98
|
+
gs.get_attribute_by_name(attribute_name)
|
99
|
+
|
100
|
+
The following call will return all products linked to the retailer\_product\_id listed.
|
101
|
+
|
102
|
+
gs.get_product_links(retailer_product_id)
|
103
|
+
|
104
|
+
###Interact with User Data
|
105
|
+
The following will return the user data of the gs.session\_id. The user\_id param is optional.
|
106
|
+
|
107
|
+
gs.get_user_data(user_id)
|
108
|
+
|
109
|
+
The following call accepts session\_data (it can be anything you want to save). And it save it to the user data.
|
110
|
+
|
111
|
+
gs.save_user_data(session_data, user_id)
|
112
|
+
|
113
|
+
###Reporting calls
|
114
|
+
|
115
|
+
The following call records recommendation based on the gs.session\_id. You will need to pass the group id and the retailer product list (not optional).
|
116
|
+
|
117
|
+
gs.recs(group_id, retailer_product_list)
|
118
|
+
|
119
|
+
The following call will record the event passed on the gs.session\_id.
|
120
|
+
|
121
|
+
gs.record_events(event_name)
|
122
|
+
|
123
|
+
The following call will record microconversion based on the gs.session\_id and the retailer product id passed (param not optional).
|
124
|
+
gs.micro_convert(retailer_product_id)
|
125
|
+
|
126
|
+
###PG CI interaction
|
127
|
+
|
128
|
+
Since we often need to pull CI buy now info for PG products. The GS::Ci module will allow you to pass a sku and an rgid value (usually provided
|
129
|
+
by the vendor to retreive an array of vendors, vendor logo images and buy now links to build the buy now button for a
|
130
|
+
specific product.
|
131
|
+
|
132
|
+
ci = GS::Ci.new
|
133
|
+
buy_now_array = ci.buy_now(pg_product_id, rgid)
|
134
|
+
|
135
|
+
The previous call will return:
|
136
|
+
|
137
|
+
[
|
138
|
+
{
|
139
|
+
:id=>"Product Id",
|
140
|
+
:logo=>"Retailer Logo Image",
|
141
|
+
:name=>"Retailer Name",
|
142
|
+
:buy_now_link=>"Buy now Button",
|
143
|
+
:product_name=>"Product Name",
|
144
|
+
:price=>"Price",
|
145
|
+
:product_image=>"Product Image",
|
146
|
+
:available=>"Y or N"
|
147
|
+
}
|
148
|
+
]
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
---
|
153
|
+
|
154
|
+
####Contributing to goldshark\_gem
|
155
|
+
|
156
|
+
Gabriele Roselli
|
157
|
+
|
158
|
+
Copyright
|
159
|
+
|
160
|
+
Copyright (c) 2012 iGoDigital. See LICENSE.txt for
|
161
|
+
further details.
|
162
|
+
|
data/goldshark_gem.gemspec
CHANGED
@@ -7,5 +7,11 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.summary = %q{A gem to interact with iGodigital GoldShark API}
|
8
8
|
s.description = %q{A gem to interact with iGodigital GoldShark API}
|
9
9
|
s.files = `git ls-files`.split($\)
|
10
|
-
|
10
|
+
s.extra_rdoc_files = [
|
11
|
+
"README.md"
|
12
|
+
]
|
13
|
+
s.add_dependency 'activesupport', "~> 3.2.8"
|
14
|
+
s.add_dependency 'libxml-ruby'
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
s.version = '0.1.2'
|
11
17
|
end
|
data/lib/goldshark_gem.rb
CHANGED
@@ -1,247 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'net/http'
|
2
3
|
require 'net/https'
|
3
4
|
require 'uri'
|
4
5
|
require 'json'
|
5
6
|
require 'yaml'
|
7
|
+
require 'active_support/all'
|
8
|
+
require 'xml/libxml'
|
6
9
|
|
7
|
-
|
8
|
-
|
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
|
10
|
+
require "#{File.dirname(__FILE__)}/goldshark_gem"
|
11
|
+
Dir["#{File.dirname(__FILE__)}/goldshark_gem/*.rb"].each { |file| require file.gsub(".rb", "")}
|