simple_relevance 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +24 -0
- data/README.md +4 -0
- data/lib/simple_relevance.rb +73 -0
- data/lib/simple_relevance/version.rb +3 -0
- data/simple_relevance.gemspec +18 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/tmp_spec.rb +7 -0
- metadata +66 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Nothing so far.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
httparty (0.9.0)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
multi_xml
|
8
|
+
multi_json (1.3.7)
|
9
|
+
multi_xml (0.5.1)
|
10
|
+
rspec (2.11.0)
|
11
|
+
rspec-core (~> 2.11.0)
|
12
|
+
rspec-expectations (~> 2.11.0)
|
13
|
+
rspec-mocks (~> 2.11.0)
|
14
|
+
rspec-core (2.11.1)
|
15
|
+
rspec-expectations (2.11.3)
|
16
|
+
diff-lcs (~> 1.1.3)
|
17
|
+
rspec-mocks (2.11.3)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
httparty
|
24
|
+
rspec
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
# A Ruby API wrapper for SimpleRelevance
|
5
|
+
# free to use and unlicensed
|
6
|
+
# requires httparty
|
7
|
+
|
8
|
+
# you can get an API key by signing up for SimpleRelevance on the site. Signup is free.
|
9
|
+
# async: when you are done testing, set async=1. This will speed up API response times by a factor of 2 or 3.
|
10
|
+
# predictions: this is the part of SimpleRelevance that eventually costs money to use. They will not be available right away, as our automated model builds happen nightly. Please get in touch during business hours (inquiries@simplerelevance.com) if you want us to build a model sooner.
|
11
|
+
|
12
|
+
# documentation: note that documentation is available at simplerelevance.com/docs/api2
|
13
|
+
|
14
|
+
# also, I have not used ruby in more than a year, so I apologize for creaky/ugly code. Anyway, all functionality has been tested.
|
15
|
+
|
16
|
+
# BATCH MODE: note that converting to use batch mode is easy - all POST requests accept a list, as you can see, so simply modify the requests to take a list of hashes as input.
|
17
|
+
|
18
|
+
class SimpleRelevance
|
19
|
+
include HTTParty
|
20
|
+
|
21
|
+
def initialize(key,async=0)
|
22
|
+
@api_key=key
|
23
|
+
@async=async
|
24
|
+
end
|
25
|
+
|
26
|
+
def _post(endpoint,post_data)
|
27
|
+
data = {:api_key=>@api_key,:async=>@async,:data=>post_data}
|
28
|
+
self.class.post("https://simplerelevance.com/api/v2/#{endpoint}",:body => JSON.dump(data), :options => {:headers => {'Content-Type'=>'application/json', :accept =>'application/json'}})
|
29
|
+
end
|
30
|
+
|
31
|
+
def _get(endpoint,get_data)
|
32
|
+
data = {:api_key=>@api_key,:async=>@async}
|
33
|
+
data.merge!(get_data)
|
34
|
+
puts data
|
35
|
+
self.class.get("https://simplerelevance.com/api/v2/#{endpoint}",:query => data)
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_user(email,opts={})
|
39
|
+
zipcode = opts[:zipcode] || nil
|
40
|
+
user_id = opts[:user_id] || nil
|
41
|
+
data_dict = opts[:data_dict] || {}
|
42
|
+
|
43
|
+
payload = [{:email=>email,:zipcode=>zipcode,:user_id=>user_id,:data_dict=>data_dict}]
|
44
|
+
self._post('users/',payload)
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_item(item_name,item_id,opts={})
|
48
|
+
item_type = opts[:item_type] || 'product'
|
49
|
+
data_dict = opts[:data_dict] || {}
|
50
|
+
variants = opts[:variants] || {}
|
51
|
+
|
52
|
+
payload = [{:item_name=>item_name,:item_id=>item_id,:item_type=>item_type,:data_dict=>data_dict,:variants=>variants}]
|
53
|
+
self._post('items/',payload)
|
54
|
+
end
|
55
|
+
|
56
|
+
# action_hook should be "clicks/" or "purchases/"
|
57
|
+
# takes: action_hook="purchases/",user_id=nil,item_id=nil,email=nil,item_name=nil,timestamp=nil,price=nil,zipcode=nil
|
58
|
+
|
59
|
+
def add_action(opts={})
|
60
|
+
action_hook = opts[:action_hook] || "purchases/"
|
61
|
+
opts.delete(:action_hook)
|
62
|
+
payload = [opts]
|
63
|
+
self._post(action_hook,payload)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def get_predictions(email,opts={})
|
68
|
+
opts[:email]=email
|
69
|
+
self._get('items/',opts)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'simple_relevance/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'simple_relevance'
|
6
|
+
s.version = SimpleRelevance::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ['Declan Frye', 'Eli Albert']
|
9
|
+
s.email = 'deckleberryfrye@gmail.com'
|
10
|
+
s.summary = 'Ruby wrapper to SimpleRelevance API.'
|
11
|
+
s.description = 'Ruby wrapper to SimpleRelevance API. Allows you to upload data and to pull down recommendations.'
|
12
|
+
|
13
|
+
s.add_dependency 'httparty'
|
14
|
+
# s.add_development_dependency 'rspec' # What does this do, exactly?
|
15
|
+
|
16
|
+
s.require_paths = ['lib']
|
17
|
+
s.files = `git ls-files`.split($\)
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
data/spec/tmp_spec.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
sr = SimpleRelevance.new('KEY HERE',async=0)
|
4
|
+
puts sr.add_user("iamnew@gmail.com",opts={:data_dict=>{:testingagain=>"2"}})
|
5
|
+
puts sr.add_item("anotheritemtest",67,opts={:data_dict=>{:testattr=>"wahoo"}})
|
6
|
+
puts sr.add_action({:action_hook=>"purchases",:email=>'anotherone23@gmail.com',:item_id=>66,:timestamp=>"12/24/2011 01:23:56"})
|
7
|
+
puts sr.get_predictions('thisisforlater@gmail.com')
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_relevance
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Declan Frye
|
9
|
+
- Eli Albert
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-11-02 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
requirement: &73664280 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *73664280
|
26
|
+
description: Ruby wrapper to SimpleRelevance API. Allows you to upload data and to
|
27
|
+
pull down recommendations.
|
28
|
+
email: deckleberryfrye@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- Gemfile.lock
|
36
|
+
- README.md
|
37
|
+
- lib/simple_relevance.rb
|
38
|
+
- lib/simple_relevance/version.rb
|
39
|
+
- simple_relevance.gemspec
|
40
|
+
- spec/spec_helper.rb
|
41
|
+
- spec/tmp_spec.rb
|
42
|
+
homepage:
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.10
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Ruby wrapper to SimpleRelevance API.
|
66
|
+
test_files: []
|