Class: FourTell
- Inherits:
-
Object
- Object
- FourTell
- Defined in:
- lib/four_tell.rb,
lib/four_tell/request.rb
Defined Under Namespace
Classes: Request
Constant Summary collapse
- VERSION =
"1.0.0"
Instance Method Summary collapse
- #build_request ⇒ FourTell::Request
-
#initialize(api_user, api_password, client_alias) ⇒ FourTell
constructor
A new instance of FourTell.
-
#recommendations(request, timeout: 3) ⇒ Array
Retrieve a list of recommended product IDs for a given request.
Constructor Details
#initialize(api_user, api_password, client_alias) ⇒ FourTell
Returns a new instance of FourTell.
12 13 14 15 16 |
# File 'lib/four_tell.rb', line 12 def initialize(api_user, api_password, client_alias) @api_user = api_user @api_password = api_password @client_alias = client_alias end |
Instance Method Details
#build_request ⇒ FourTell::Request
36 37 38 |
# File 'lib/four_tell.rb', line 36 def build_request FourTell::Request.new(@client_alias) end |
#recommendations(request, timeout: 3) ⇒ Array
Retrieve a list of recommended product IDs for a given request.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/four_tell.rb', line 24 def recommendations(request, timeout: 3) url = URI(request.url) response = Timeout::timeout(timeout) { http = Net::HTTP::Persistent.new 'fourtell' req = Net::HTTP::Get.new(url.request_uri) req.basic_auth(@api_user, @api_password) http.request(url, req) } (response && response.code == '200') ? JSON.parse(response.body) : [] end |