lymbix 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +26 -0
- data/LICENSE +1 -0
- data/README +36 -0
- data/lib/lymbix.rb +218 -0
- data/lib/lymbix/base.rb +215 -0
- data/lib/lymbix/connotative_category.rb +15 -0
- data/lib/lymbix/data_point.rb +61 -0
- data/lib/lymbix/request.rb +57 -0
- data/lib/lymbix/response.rb +27 -0
- data/lib/lymbix/tweet.rb +15 -0
- data/lib/lymbix/user.rb +96 -0
- data/lib/lymbix/word.rb +78 -0
- metadata +76 -0
data/Changelog
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
v0.3.1 - rechanged dominant_words to use dominant_words on gyrus
|
2
|
+
v0.3.0 - changed dominant_words to post to dominants in gyrus instead of dominant_words, removed dominant_words_limit, removed promote method since we won't use it
|
3
|
+
v0.2.9 - fix response to_s
|
4
|
+
v0.2.8 - tonecheck beta functionality
|
5
|
+
v0.2.7 - added archive_user_data
|
6
|
+
v0.2.6 - changes for Medulla ratings reviewing
|
7
|
+
v0.2.5 - changes for Medulla release
|
8
|
+
v0.2.4 - gold data and new user fields (demographic information)
|
9
|
+
v0.2.3 - added last_checkout_date param to bad_ratings_count method
|
10
|
+
v0.2.2 - added method to get bad ratings count for toneaday users
|
11
|
+
v0.2.1 - changed the response for DataPoint.create method, added :phrase param to be able to rate words with gem
|
12
|
+
v0.2.0 - included the :worker_id parameter for data_points, added dominant_words_limit method, you can specify how many words you want back
|
13
|
+
v0.2.0 - changed response to json for contribution_count
|
14
|
+
v0.2.0 - added create method DataPoint
|
15
|
+
v0.1.7 - expunge method added
|
16
|
+
v0.1.6 - passing lymbix_user_id on authorize
|
17
|
+
v0.1.5 - authentication returns xml or json
|
18
|
+
v0.1.4 - Added open bar authentication
|
19
|
+
v0.0.8 - Added user fields for update and authenticate
|
20
|
+
v0.0.7 - error messages
|
21
|
+
v0.0.6 - production urlsponse
|
22
|
+
v0.0.5 - added files in gemspec
|
23
|
+
v0.0.4 - Working prototype, more classes
|
24
|
+
v0.0.3 - Put functionality in different files, request and base for now
|
25
|
+
v0.0.2 - Changing the gem to connect to fornix for authentication
|
26
|
+
v0.0.1 - Built gem
|
data/LICENSE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Lymbix
|
data/README
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
= Lymbix
|
2
|
+
|
3
|
+
Lymbix gives you the ability to determine the tone of any phrase or passage.
|
4
|
+
|
5
|
+
@lymbix.tonalize_phrase "This is a test passage"
|
6
|
+
|
7
|
+
To be able to access this resource - please go to http://www.toneapi.com and create an account. You need to agree to the licensing terms, and your account needs to be approved.
|
8
|
+
|
9
|
+
Some resources to help you along the way:
|
10
|
+
|
11
|
+
#Add resources
|
12
|
+
|
13
|
+
== Example usage
|
14
|
+
|
15
|
+
Authentication:
|
16
|
+
|
17
|
+
@lymbix = Lymbix::Base.authenticate('user@example.com','secretpassword', application_id)
|
18
|
+
|
19
|
+
Get the tone of words/phrases:
|
20
|
+
|
21
|
+
@lymbix.tonalize_phrase "This is a test passage"
|
22
|
+
|
23
|
+
Connotative Categories:
|
24
|
+
|
25
|
+
@lymbix.all_connotative_categories
|
26
|
+
|
27
|
+
Database Size:
|
28
|
+
|
29
|
+
@lymbix.word_count
|
30
|
+
|
31
|
+
|
32
|
+
== Authors and credits
|
33
|
+
|
34
|
+
Authors:: Pat Roy, Josh Merchant
|
35
|
+
Copyright:: Lymbix Inc
|
36
|
+
License:: Subject to licensing terms - see http://www.toneapi.com
|
data/lib/lymbix.rb
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
2
|
+
|
3
|
+
require 'lymbix/user'
|
4
|
+
require 'lymbix/request'
|
5
|
+
require 'lymbix/response'
|
6
|
+
require 'lymbix/word'
|
7
|
+
require 'lymbix/base'
|
8
|
+
require 'lymbix/connotative_category'
|
9
|
+
require 'lymbix/tweet'
|
10
|
+
require 'lymbix/data_point'
|
11
|
+
|
12
|
+
|
13
|
+
# require 'rest_client'
|
14
|
+
# require 'json'
|
15
|
+
# require 'benchmark'
|
16
|
+
#
|
17
|
+
# module Lymbix
|
18
|
+
#
|
19
|
+
# GYRUS_URL = "http://localhost:4567"
|
20
|
+
# FORNIX_URL = "http://localhost:9393"
|
21
|
+
#
|
22
|
+
# @@auth_token = ''
|
23
|
+
# @@response = nil
|
24
|
+
#
|
25
|
+
# cattr_accessor :auth_token
|
26
|
+
#
|
27
|
+
#
|
28
|
+
# def self.request(resource, action = "get", object = nil, fornix = false)
|
29
|
+
# result = nil
|
30
|
+
# connection = RestClient::Resource.new(fornix ? FORNIX_URL : GYRUS_URL, :headers => { :AUTHENTICATION => @@auth_token })
|
31
|
+
# case(action)
|
32
|
+
# when "get"
|
33
|
+
# result = connection[resource].get
|
34
|
+
# when "post"
|
35
|
+
# result = connection[resource].post object
|
36
|
+
# end
|
37
|
+
# result
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# #--------------------------------------------------------------------------
|
41
|
+
# # BaseObject
|
42
|
+
# #==========================================================================
|
43
|
+
#
|
44
|
+
# class BaseObject < Struct
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# #--------------------------------------------------------------------------
|
48
|
+
# # Users
|
49
|
+
# #==========================================================================
|
50
|
+
#
|
51
|
+
# User = BaseObject.new(:id, :login, :email, :gender, :country, :state, :age)
|
52
|
+
#
|
53
|
+
# class User
|
54
|
+
#
|
55
|
+
# def self.authenticate(login, password)
|
56
|
+
# resp = Lymbix::request("login", "post", {:login => login, :password => password}, true)
|
57
|
+
# return nil if resp == "null"
|
58
|
+
#
|
59
|
+
# user = JSON.load(resp)
|
60
|
+
#
|
61
|
+
# User.new(user["id"], user["login"], user["email"], user["gender"], user["country"], user["state"], user["age"])
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# #--------------------------------------------------------------------------
|
67
|
+
# # Words
|
68
|
+
# #==========================================================================
|
69
|
+
#
|
70
|
+
# Word = BaseObject.new(:id, :word, :is_external, :is_phrase)
|
71
|
+
#
|
72
|
+
# #<struct Lymbix::Word id={:is_external=>false, :id=>34941, :word=>"demand"}, word=nil, is_external=nil>
|
73
|
+
#
|
74
|
+
# class Word
|
75
|
+
#
|
76
|
+
# def self.count
|
77
|
+
# resp = Lymbix::request('word_count')
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# def self.top_random
|
81
|
+
# resp = Lymbix::request('top_random')
|
82
|
+
# word = JSON.load(resp)
|
83
|
+
#
|
84
|
+
# return nil if word.nil? || word.empty?
|
85
|
+
# Word.new(word["id"], word["word"], word["is_external"], word["is_phrase"])
|
86
|
+
# end
|
87
|
+
#
|
88
|
+
# def self.add_word(word, definition, is_phrase = false)
|
89
|
+
# resp = Lymbix::request('words', 'post', {:word => word, :definition => definition, :is_external => true, :is_phrase => is_phrase})
|
90
|
+
# word = JSON.load(resp)
|
91
|
+
# return nil if word.nil? || word.empty?
|
92
|
+
# Word.new(word["id"], word["word"], word["is_external"], word["is_phrase"])
|
93
|
+
# end
|
94
|
+
#
|
95
|
+
# def self.lookup(word)
|
96
|
+
# resp = Lymbix::request("lookup/#{word}")
|
97
|
+
# return nil if resp == "null"
|
98
|
+
#
|
99
|
+
# word = JSON.load(resp)
|
100
|
+
#
|
101
|
+
# return nil if word.nil? || word.empty?
|
102
|
+
# Word.new(word["id"], word["word"], word["is_external"], word["is_phrase"])
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
# def self.search(word)
|
106
|
+
# resp = Lymbix::request("search/#{word}")
|
107
|
+
# word = JSON.load(resp)
|
108
|
+
#
|
109
|
+
# return nil if word.nil? || word.empty?
|
110
|
+
# Word.new(word["id"], word["word"], word["is_external"], word["is_phrase"])
|
111
|
+
# end
|
112
|
+
#
|
113
|
+
# def self.find(word_id)
|
114
|
+
# resp = Lymbix::request("words/#{word_id}")
|
115
|
+
# word = JSON.load(resp)
|
116
|
+
#
|
117
|
+
# return nil if word.nil? || word.empty?
|
118
|
+
# Word.new(word["id"], word["word"], word["is_external"], word["is_phrase"])
|
119
|
+
# end
|
120
|
+
#
|
121
|
+
# def definitions
|
122
|
+
# Definition::list(self.id)
|
123
|
+
# end
|
124
|
+
#
|
125
|
+
# end
|
126
|
+
#
|
127
|
+
# #--------------------------------------------------------------------------
|
128
|
+
# # Tweets
|
129
|
+
# #==========================================================================
|
130
|
+
#
|
131
|
+
# Tweet = BaseObject.new(:id, :is_user_created, :tweet, :requested_count)
|
132
|
+
#
|
133
|
+
# class Tweet
|
134
|
+
#
|
135
|
+
# def self.top_tweet
|
136
|
+
# resp = Lymbix::request('top_tweet')
|
137
|
+
# resp = JSON.load(resp)
|
138
|
+
#
|
139
|
+
# return nil if resp.nil?
|
140
|
+
# Tweet.new(resp["id"], resp["is_user_created"], resp["tweet"], resp["requested_count"])
|
141
|
+
# end
|
142
|
+
#
|
143
|
+
# end
|
144
|
+
#
|
145
|
+
#
|
146
|
+
# #--------------------------------------------------------------------------
|
147
|
+
# # Definitions
|
148
|
+
# #==========================================================================
|
149
|
+
#
|
150
|
+
# Definition = BaseObject.new(:id, :pos, :category_id, :definition)
|
151
|
+
#
|
152
|
+
# class Definition
|
153
|
+
#
|
154
|
+
# def self.list(word_id)
|
155
|
+
# resp = Lymbix::request("word/#{word_id}/definitions") #Change to Words
|
156
|
+
# definitions = JSON.load(resp)
|
157
|
+
# definition_list = []
|
158
|
+
# definitions.each do |definition|
|
159
|
+
# definition_list << Definition.new(definition["id"], definition["pos"], definition["category_id"], definition["definition"])
|
160
|
+
# end
|
161
|
+
# definition_list
|
162
|
+
# end
|
163
|
+
#
|
164
|
+
# def self.find(definition_id)
|
165
|
+
# resp = Lymbix::request("definitions/#{definition_id}")
|
166
|
+
# definition = JSON.load(resp)
|
167
|
+
# Definition.new(definition["id"], definition["pos"], definition["category_id"], definition["definition"])
|
168
|
+
# end
|
169
|
+
#
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
# #--------------------------------------------------------------------------
|
173
|
+
# # ConnotativeCategory
|
174
|
+
# #==========================================================================
|
175
|
+
#
|
176
|
+
# ConnotativeCategory = BaseObject.new(:id, :name, :is_positive)
|
177
|
+
#
|
178
|
+
# class ConnotativeCategory
|
179
|
+
# def self.all
|
180
|
+
# resp = Lymbix::request("connotative_categories")
|
181
|
+
# connotative_categories = JSON.load(resp)
|
182
|
+
# connotative_categories_list = []
|
183
|
+
# connotative_categories.each do |connotative_category|
|
184
|
+
# connotative_categories_list << ConnotativeCategory.new(connotative_category["id"], connotative_category["name"], connotative_category["is_positive"])
|
185
|
+
# end
|
186
|
+
# puts connotative_categories_list.inspect
|
187
|
+
# connotative_categories_list
|
188
|
+
# end
|
189
|
+
#
|
190
|
+
# def self.find(id)
|
191
|
+
# resp = Lymbix::request("connotative_categories/#{id}")
|
192
|
+
# connotative_category = JSON.load(resp)
|
193
|
+
# ConnotativeCategory.new(connotative_category["id"], connotative_category["name"], connotative_category["is_positive"])
|
194
|
+
# end
|
195
|
+
# end
|
196
|
+
#
|
197
|
+
# #--------------------------------------------------------------------------
|
198
|
+
# # DataPoint
|
199
|
+
# #==========================================================================
|
200
|
+
#
|
201
|
+
# DataPoint = BaseObject.new(:id, :word_id, :definition_id, :category_id, :data, :created_at, :updated_at, :user_id)
|
202
|
+
#
|
203
|
+
# class DataPoint
|
204
|
+
# def save
|
205
|
+
# resp = Lymbix::request("data_points", "post", {:word_id => self["word_id"], :definition_id => self["definition_id"], :category_id => self["category_id"], :data => self["data"], :user_id => self["user_id"]})
|
206
|
+
# data_point = JSON.load(resp)
|
207
|
+
# DataPoint.new(data_point["id"], data_point["word_id"], data_point["definition_id"], data_point["category_id"], data_point["data"], data_point["created_at"], data_point["updated_at"], data_point["user_id"])
|
208
|
+
# end
|
209
|
+
#
|
210
|
+
# def self.find(data_point_id)
|
211
|
+
# resp = Lymbix::request("data_points/#{data_point_id}")
|
212
|
+
# data_point = JSON.load(resp)
|
213
|
+
# DataPoint.new(data_point["id"], data_point["word_id"], data_point["definition_id"], data_point["category_id"], data_point["data"], data_point["created_at"], data_point["updated_at"], data_point["user_id"])
|
214
|
+
# end
|
215
|
+
#
|
216
|
+
# end
|
217
|
+
#
|
218
|
+
# end
|
data/lib/lymbix/base.rb
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
module Lymbix
|
2
|
+
|
3
|
+
class Base
|
4
|
+
attr_accessor :auth_key, :app_id, :lymbix_user_id, :error_messages, :user
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
unless options[:error_messages]
|
8
|
+
@auth_key = options[:auth_key]
|
9
|
+
@app_id = options[:app_id]
|
10
|
+
@lymbix_user_id = options[:lymbix_user_id]
|
11
|
+
@user = User.new(options[:user].merge({:auth_key => options[:auth_key]})) if options[:user]
|
12
|
+
if @user
|
13
|
+
@lymbix_user_id = @user.lymbix_user_id
|
14
|
+
end
|
15
|
+
else
|
16
|
+
@error_messages = options[:error_messages]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def open_bar_auth_key(options)
|
21
|
+
response = Lymbix::Request.new(:post, 'open_bar_auth_key', {:lymbix_user_id => options[:lymbix_user_id], :auth_key => options[:auth_key], :app_id => options[:app_id]}, :app_id => options[:app_id], :other_app_id => options[:other_app_id]).run
|
22
|
+
response.data["auth_key"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.authenticate(email, password, app_id)
|
26
|
+
response = Lymbix::Request.new(:post, 'authenticate', {:app_id => app_id}, {:app_id => app_id, :email => email, :password => password}).run
|
27
|
+
hash_response = response.data.to_hash
|
28
|
+
self.new(:auth_key => hash_response["auth_key"], :app_id => app_id, :user => {:name => hash_response["name"], :age => hash_response["age"], :country => hash_response["country"], :state => hash_response["state"], :lymbix_user_id => hash_response["id"], :gender => hash_response["gender"], :error_messages => []})
|
29
|
+
rescue RestClient::Unauthorized
|
30
|
+
self.new(:error_messages => "Wrong Password")
|
31
|
+
rescue Exception => ex
|
32
|
+
self.new(:error_messages => "#{ex.message} \n #{ex.backtrace}")
|
33
|
+
end
|
34
|
+
|
35
|
+
def service_up
|
36
|
+
response = request(:get, 'service_up').data
|
37
|
+
end
|
38
|
+
|
39
|
+
def word_count
|
40
|
+
response = request(:get, 'word_count').data
|
41
|
+
response["count"].to_i
|
42
|
+
end
|
43
|
+
|
44
|
+
def contribution_count
|
45
|
+
response = request(:get, 'contribution_count').data
|
46
|
+
response["contribution_count"].to_i
|
47
|
+
end
|
48
|
+
|
49
|
+
def toneaday_daily_best
|
50
|
+
response = request(:get, 'toneaday_daily_best').data
|
51
|
+
puts response["daily_toneaday_user_id"].to_i
|
52
|
+
[response["daily_toneaday_user_id"].to_i, response["daily_toneaday_contribution_count"].to_i]
|
53
|
+
end
|
54
|
+
|
55
|
+
def toneaday_weekly_best
|
56
|
+
response = request(:get, 'toneaday_weekly_best').data
|
57
|
+
[response["weekly_toneaday_user_id"].to_i, response["weekly_toneaday_contribution_count"].to_i]
|
58
|
+
end
|
59
|
+
|
60
|
+
def user_contribution_count(user_id)
|
61
|
+
response = request(:get, "contribution_count/#{user_id}").data
|
62
|
+
response["contribution_count"].to_i
|
63
|
+
end
|
64
|
+
|
65
|
+
def tonalized_words_count
|
66
|
+
response = request(:get, 'tonalized_words').data
|
67
|
+
response["tonalized_words_count"].to_i
|
68
|
+
end
|
69
|
+
|
70
|
+
def word_top_random
|
71
|
+
response = request(:get, 'word_top_random')
|
72
|
+
Word.new(:id => response.data["id"], :word => response.data["word"], :is_external => response.data["is_external"], :is_phrase => response.data["is_phrase"])
|
73
|
+
end
|
74
|
+
|
75
|
+
def gold_word_top_random
|
76
|
+
response = request(:get, 'gold_word_top_random')
|
77
|
+
Word.new(:id => response.data["id"], :word => response.data["word"], :is_external => response.data["is_external"], :is_phrase => response.data["is_phrase"])
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def word_lookup(word)
|
82
|
+
response = request(:get, "lookup/#{URI.escape(word)}")
|
83
|
+
if response.data
|
84
|
+
Word.new(:id => response.data["id"], :word => response.data["word"], :is_external => response.data["is_external"], :is_phrase => response.data["is_phrase"])
|
85
|
+
else
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def add_word(word, definition, is_phrase = false)
|
91
|
+
ActiveRecord::Base.logger.info "ADD_WORD START"
|
92
|
+
response = request(:post, 'words', {:word => word, :definition => definition, :is_external => true, :is_phrase => is_phrase})
|
93
|
+
ActiveRecord::Base.logger.info "ADD_WORD END #{response.inspect}"
|
94
|
+
Word.new(:id => response.data["id"], :word => response.data["word"], :is_external => response.data["is_external"], :is_phrase => response.data["is_phrase"])
|
95
|
+
end
|
96
|
+
|
97
|
+
def bad_ratings_count(user_id,last_checkout_date)
|
98
|
+
response = request(:get, "bad_ratings_count/#{user_id}/#{last_checkout_date}")
|
99
|
+
end
|
100
|
+
|
101
|
+
def expunge(word)
|
102
|
+
response = request(:post,'expunge', {:word => word})
|
103
|
+
end
|
104
|
+
|
105
|
+
# MODERATION
|
106
|
+
|
107
|
+
def approve_tonecheck_beta(user_id)
|
108
|
+
response = request(:post, 'approve_tonecheck_beta', {:user_id => user_id})
|
109
|
+
end
|
110
|
+
|
111
|
+
def reset_tonecheck_beta(user_id)
|
112
|
+
response = request(:post, 'reset_tonecheck_beta', {:user_id => user_id})
|
113
|
+
end
|
114
|
+
|
115
|
+
def tonecheck_beta_count
|
116
|
+
response = request(:get, 'tonecheck_beta_count', {:app_id => @app_id})
|
117
|
+
response.data['tonecheck_beta_count']
|
118
|
+
end
|
119
|
+
|
120
|
+
def tonecheck_beta
|
121
|
+
response = request(:get, 'tonecheck_beta', {:app_id => @app_id})
|
122
|
+
response.data['tonecheck_beta']
|
123
|
+
end
|
124
|
+
|
125
|
+
def moderated_count
|
126
|
+
response = request(:get, 'moderated_count', {:app_id => @app_id})
|
127
|
+
response.data['moderated_count']
|
128
|
+
end
|
129
|
+
|
130
|
+
def unmoderated_count
|
131
|
+
response = request(:get, 'unmoderated_count', {:app_id => @app_id})
|
132
|
+
response.data['unmoderated_count']
|
133
|
+
end
|
134
|
+
|
135
|
+
def moderated
|
136
|
+
response = request(:get, 'moderated', {:app_id => @app_id})
|
137
|
+
response.data['moderated']
|
138
|
+
end
|
139
|
+
|
140
|
+
def unmoderated
|
141
|
+
response = request(:get, 'unmoderated', {:app_id => @app_id})
|
142
|
+
response.data['unmoderated']
|
143
|
+
end
|
144
|
+
|
145
|
+
def user_data_points(user_id, page = 1, earnings_in_cents = 0)
|
146
|
+
response = request(:get, "user_data_points/#{user_id}/#{page}/#{earnings_in_cents}", {:app_id => @app_id})
|
147
|
+
response.data['data']
|
148
|
+
end
|
149
|
+
|
150
|
+
def user_search(query)
|
151
|
+
response = request(:post, "user_search", {:app_id => @app_id, :query => query})
|
152
|
+
response.data['users']
|
153
|
+
end
|
154
|
+
|
155
|
+
def find_user_by_id(user_id)
|
156
|
+
response = request(:post, "find_user_by_id", {:app_id => @app_id, :user_id => user_id})
|
157
|
+
response.data['user']
|
158
|
+
end
|
159
|
+
|
160
|
+
def find_users_by_ids(user_ids)
|
161
|
+
response = request(:post, "find_users_by_ids", {:app_id => @app_id, :user_ids => user_ids.join(',')})
|
162
|
+
response.data['users']
|
163
|
+
end
|
164
|
+
|
165
|
+
def archive_user_data(user_id)
|
166
|
+
response = request(:post, "archive_user_data/#{user_id}", {:app_id => @app_id})
|
167
|
+
response
|
168
|
+
end
|
169
|
+
|
170
|
+
# END
|
171
|
+
|
172
|
+
def tonalize_words(phrase)
|
173
|
+
response = request(:post, 'tonalize_words', {:phrase => phrase}).data
|
174
|
+
end
|
175
|
+
|
176
|
+
def tone_alternates(phrase)
|
177
|
+
response = request(:post, 'suggestions',{:phrase => phrase}).data
|
178
|
+
end
|
179
|
+
|
180
|
+
def suggest_alternates(phrase,alternates)
|
181
|
+
response = request(:post, 'suggest_alternates',{:phrase => phrase, :alternates => alternates}).data
|
182
|
+
end
|
183
|
+
|
184
|
+
def all_connotative_categories
|
185
|
+
response = request(:get, 'connotative_categories')
|
186
|
+
all_cc = []
|
187
|
+
response.data.each do |cc|
|
188
|
+
all_cc << ConnotativeCategory.new(:id => cc["id"], :name => cc["name"], :is_positive => cc["is_positive"])
|
189
|
+
end
|
190
|
+
all_cc
|
191
|
+
end
|
192
|
+
|
193
|
+
def top_tweet
|
194
|
+
response = request(:get, 'top_tweet').data
|
195
|
+
tweet = Tweet.new(:id => response["id"], :is_user_created => response["is_user_created"], :tweet => response["tweet"], :requested_count => response["requested_count"])
|
196
|
+
tweet.instance_variable_set(:@phrases_found,response["phrases_found"])
|
197
|
+
return tweet
|
198
|
+
end
|
199
|
+
|
200
|
+
def dominant_words(phrase)
|
201
|
+
response = request(:post, 'dominant_words',{:phrase => phrase}).data
|
202
|
+
end
|
203
|
+
|
204
|
+
def swap_groups(lymbix_user_id, group_remove, group_add)
|
205
|
+
response = request(:post, 'swap_groups', {:lymbix_user_id => lymbix_user_id, :group_remove => group_remove, :group_add => group_add})
|
206
|
+
end
|
207
|
+
|
208
|
+
private
|
209
|
+
def request(action, method, data = nil)
|
210
|
+
Lymbix::Request.new(action, method, {:app_id => @app_id, :auth_key => @auth_key, :lymbix_user_id => @lymbix_user_id}, data).run
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Lymbix
|
2
|
+
|
3
|
+
class DataPoint
|
4
|
+
|
5
|
+
attr_accessor :id, :word_id, :definition_id, :category_id, :data, :created_at, :updated_at, :user_id, :auth_key, :app_id, :lymbix_user_id
|
6
|
+
|
7
|
+
def initialize(data = nil)
|
8
|
+
if data
|
9
|
+
@id = data[:id]
|
10
|
+
@word_id = data[:word_id]
|
11
|
+
@definition_id = data[:definition_id]
|
12
|
+
@category_id = data[:category_id]
|
13
|
+
@data = data[:data]
|
14
|
+
@created_at = data[:created_at]
|
15
|
+
@updated_at = data[:updated_at]
|
16
|
+
@user_id = data[:user_id]
|
17
|
+
@app_id = data[:app_id]
|
18
|
+
@auth_key = data[:auth_key]
|
19
|
+
@lymbix_user_id = data[:lymbix_user_id]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.create(data)
|
24
|
+
categories_data = "{"
|
25
|
+
data[:data_points].each do |dp|
|
26
|
+
categories_data << ":category_id_#{dp[:category_id]} => #{dp[:data]},"
|
27
|
+
end
|
28
|
+
categories_data.chop!
|
29
|
+
categories_data << "}"
|
30
|
+
response = Lymbix::Request.new(:post, "data_points",{:app_id => data[:app_id], :auth_key => data[:auth_key], :lymbix_user_id => data[:lymbix_user_id]}, {:worker_id => data[:worker_id], :phrase => data[:phrase], :word_id => data[:word_id], :definition_id => data[:definition_id], :user_id => data[:user_id], :lymbix_user_id => data[:lymbix_user_id]}.merge!(eval(categories_data))).run
|
31
|
+
end
|
32
|
+
|
33
|
+
def save
|
34
|
+
response = Lymbix::Request.new(:post, "data_points",{:app_id => @app_id, :auth_key => @auth_key, :lymbix_user_id => @lymbix_user_id}, {:word_id => @word_id, :definition_id => @definition_id, :category_id => @category_id, :data => @data, :user_id => @user_id}).run
|
35
|
+
DataPoint.new(:id => response.data["id"], :word_id => response.data["word_id"], :definition_id => response.data["definition_id"], :category_id => response.data["category_id"], :data => response.data["data"], :created_at => response.data["created_at"], :updated_at => response.data["updated_at"], :user_id => response.data["user_id"], :lymbix_user_id => response.data["lymbix_user_id"])
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# #--------------------------------------------------------------------------
|
43
|
+
# # DataPoint
|
44
|
+
# #==========================================================================
|
45
|
+
#
|
46
|
+
# DataPoint = BaseObject.new(:id, :word_id, :definition_id, :category_id, :data, :created_at, :updated_at, :user_id)
|
47
|
+
#
|
48
|
+
# class DataPoint
|
49
|
+
# def save
|
50
|
+
# resp = Lymbix::request("data_points", "post", {:word_id => self["word_id"], :definition_id => self["definition_id"], :category_id => self["category_id"], :data => self["data"], :user_id => self["user_id"]})
|
51
|
+
# data_point = JSON.load(resp)
|
52
|
+
# DataPoint.new(data_point["id"], data_point["word_id"], data_point["definition_id"], data_point["category_id"], data_point["data"], data_point["created_at"], data_point["updated_at"], data_point["user_id"])
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# def self.find(data_point_id)
|
56
|
+
# resp = Lymbix::request("data_points/#{data_point_id}")
|
57
|
+
# data_point = JSON.load(resp)
|
58
|
+
# DataPoint.new(data_point["id"], data_point["word_id"], data_point["definition_id"], data_point["category_id"], data_point["data"], data_point["created_at"], data_point["updated_at"], data_point["user_id"])
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Lymbix
|
5
|
+
class Request
|
6
|
+
# GYRUS_URL = ENV["RAILS_ENV"] == "production" ? "http://rack-gyrus.lymbix.com" : "http://localhost:4567"
|
7
|
+
GYRUS_URL = "https://gyrus.lymbix.com"
|
8
|
+
# GYRUS_URL = "http://localhost:4567"
|
9
|
+
# GYRUS_URL = "http://74.205.17.185"
|
10
|
+
# GYRUS_URL = "http://gyrus-staging.lymbix.com"
|
11
|
+
|
12
|
+
attr_accessor :url, :http_method, :response, :method, :object, :header_hash
|
13
|
+
|
14
|
+
def initialize(http_method, method, header_hash, object = nil) #:nodoc:
|
15
|
+
self.http_method = http_method
|
16
|
+
self.url = GYRUS_URL
|
17
|
+
self.method = method
|
18
|
+
self.object = object
|
19
|
+
self.header_hash = header_hash
|
20
|
+
end
|
21
|
+
|
22
|
+
def connection
|
23
|
+
options = {}
|
24
|
+
options[:headers] = {:accept => "application/json", :APP_ID => self.header_hash[:app_id].to_s, :LYMBIX_USER_ID => self.header_hash[:lymbix_user_id], :AUTHENTICATION => self.header_hash[:auth_key]}
|
25
|
+
RestClient::Resource.new(self.url, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def run
|
29
|
+
case(self.http_method)
|
30
|
+
when :get
|
31
|
+
self.connection[self.method].get do |resp|
|
32
|
+
case resp.code
|
33
|
+
when 200
|
34
|
+
self.response = resp.body
|
35
|
+
when 401
|
36
|
+
raise RestClient::Unauthorized
|
37
|
+
else
|
38
|
+
raise Exception
|
39
|
+
end
|
40
|
+
end
|
41
|
+
when :post
|
42
|
+
self.connection[self.method].post(object) do |resp|
|
43
|
+
case resp.code
|
44
|
+
when 200
|
45
|
+
self.response = resp.body
|
46
|
+
when 401
|
47
|
+
raise RestClient::Unauthorized
|
48
|
+
else
|
49
|
+
raise Exception
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
Response.new(self.response)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Lymbix
|
4
|
+
class Response
|
5
|
+
|
6
|
+
attr_accessor :data, :success
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
unless response == "null"
|
10
|
+
@data = JSON.parse(response.to_s)
|
11
|
+
unless @data.class == Array
|
12
|
+
if @data["success"] == "false"
|
13
|
+
@success = false
|
14
|
+
else
|
15
|
+
@success = true
|
16
|
+
end
|
17
|
+
else
|
18
|
+
@success = true
|
19
|
+
end
|
20
|
+
else
|
21
|
+
@success = false
|
22
|
+
@data = nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/lib/lymbix/tweet.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Lymbix
|
2
|
+
|
3
|
+
class Tweet
|
4
|
+
|
5
|
+
attr_accessor :id, :is_user_created, :tweet, :requested_count
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@id = options[:id]
|
9
|
+
@is_user_created = options[:is_user_created]
|
10
|
+
@tweet = options[:tweet]
|
11
|
+
@requested_count = options[:requested_count]
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/lib/lymbix/user.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
module Lymbix
|
2
|
+
class User
|
3
|
+
attr_accessor :auth_key, :name, :error_messages, :age, :country, :state, :gender, :first_language, :year_of_birth, :education, :level, :strikes, :lymbix_user_id, :activated_at, :email, :is_admin, :app_member
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
@auth_key = options["auth_key"] || options[:auth_key]
|
7
|
+
@name = options["name"] || options[:name]
|
8
|
+
@age = options["age"] || options[:age]
|
9
|
+
@country = options["country"] || options[:country]
|
10
|
+
@state = options["state"] || options[:state]
|
11
|
+
@gender = options["gender"] || options[:gender]
|
12
|
+
@first_language = options["first_language"] || options[:first_language]
|
13
|
+
@level = options["level"] || options[:level]
|
14
|
+
@strikes = options["strikes"] || options[:strikes]
|
15
|
+
@year_of_birth = options["year_of_birth"] || options[:year_of_birth]
|
16
|
+
@education = options["education"] || options[:education]
|
17
|
+
@error_messages = options[:error_messages]
|
18
|
+
@lymbix_user_id = options["id"] || options[:lymbix_user_id]
|
19
|
+
@activated_at = options["activated_at"] || options[:activated_at]
|
20
|
+
@email = options["email"] || options[:email]
|
21
|
+
@is_admin = options["is_admin"] || options[:is_admin]
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.auth_login(auth_key, app_id)
|
25
|
+
response = Lymbix::Request.new(:post, 'auth_login', {:app_id => app_id}, {:auth_key => auth_key}).run
|
26
|
+
self.new(response.data.to_hash)
|
27
|
+
rescue Exception => ex
|
28
|
+
self.new(:error_messages => ["#{ex.message}"])
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.authenticate(email, password, app_id)
|
32
|
+
response = Lymbix::Request.new(:post, 'authenticate', {:app_id => app_id}, {:email => email, :password => password, :app_id => app_id}).run
|
33
|
+
self.new(response.data.to_hash)
|
34
|
+
rescue RestClient::Unauthorized
|
35
|
+
self.new(:error_messages => ["Wrong Password"])
|
36
|
+
rescue Exception => ex
|
37
|
+
self.new(:error_messages => ["#{ex.message}"])
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.enable_application(params)
|
41
|
+
begin
|
42
|
+
response = Lymbix::Request.new(:post, 'enable_application', {:app_id => params[:app_id]}, {:email => params[:email], :password => params[:password]}).run
|
43
|
+
self.new(response.data.to_hash)
|
44
|
+
rescue Exception => ex
|
45
|
+
self.new(:error_messages => [ex.message])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.find_by_email(params)
|
50
|
+
begin
|
51
|
+
response = Lymbix::Request.new(:post, 'user_find_by_email', {:app_id => params[:app_id]}, {:email => params[:email]}).run
|
52
|
+
self.new(response.data.to_hash)
|
53
|
+
rescue Exception => ex
|
54
|
+
self.new(:error_messages => [ex.message])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.find_or_create(params)
|
59
|
+
|
60
|
+
begin
|
61
|
+
# response = Lymbix::Request.new(:post, 'find_user', {:app_id => @app_id, :auth_key => @auth_key, :lymbix_user_id => @lymbix_user_id}, {:email => params[:user][:email]}).run
|
62
|
+
response = Lymbix::Request.new(:post, 'find_user', {:app_id => params[:app_id]}, {:email => params[:user][:email]}).run
|
63
|
+
|
64
|
+
ActiveRecord::Base.logger.info "!! REQUEST DONE - #{response.inspect}"
|
65
|
+
|
66
|
+
unless response.data["email"]
|
67
|
+
response = Lymbix::Request.new(:post, 'users', {:app_id => params[:app_id]}, params[:user]).run #unless response.data['auth_key']
|
68
|
+
if response.data["error_messages"]
|
69
|
+
return self.new(:error_messages => response.data["error_messages"])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
self.new(response.data.to_hash)
|
74
|
+
rescue Exception => ex
|
75
|
+
ActiveRecord::Base.logger.info "!! REQUEST FAIL - #{ex.message}"
|
76
|
+
|
77
|
+
self.new(:error_messages => [ex.message])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.update(params)
|
82
|
+
response = Lymbix::Request.new(:post, 'update_user', {:lymbix_user_id => params[:lymbix_user_id], :app_id => params[:app_id], :auth_key => params[:auth_key]}, {:email => params[:email], :name => params[:name], :password => params[:password], :password_confirmation => params[:password_confirmation], :age => params[:age], :country => params[:country], :state => params[:state], :gender => params[:gender], :first_language => params[:first_language], :year_of_birth => params[:year_of_birth], :education => params[:education]}).run
|
83
|
+
if response.success
|
84
|
+
self.new(:auth_key => response.data['auth_key'], :level => response.data['level'], :strikes => response.data['strikes'], :name => response.data['name'],:age => response.data['age'], :country => response.data['country'], :state => response.data['state'],:name => response.data['name'], :gender => response.data['gender'], :first_language => response.data['first_language'], :education => response.data['education'], :year_of_birth => response.data['year_of_birth'] , :error_messages => [])
|
85
|
+
else
|
86
|
+
self.new(:error_messages => response.data.errors)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.request_tonecheck_beta(params)
|
91
|
+
response = Lymbix::Request.new(:post, 'request_tonecheck_beta', {:app_id => params[:app_id], :auth_key => params[:auth_key]}, {:user_id => params[:user_id]}).run
|
92
|
+
response.data['user']
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
data/lib/lymbix/word.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
module Lymbix
|
2
|
+
|
3
|
+
class Word
|
4
|
+
|
5
|
+
attr_reader :id, :word, :is_external, :is_phrase
|
6
|
+
|
7
|
+
def initialize(data)
|
8
|
+
@id = data[:id]
|
9
|
+
@word = word = data[:word]
|
10
|
+
@is_external = data[:is_external]
|
11
|
+
@is_phrase = data[:is_phrase]
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
# #--------------------------------------------------------------------------
|
20
|
+
# # Words
|
21
|
+
# #==========================================================================
|
22
|
+
#
|
23
|
+
# Word = BaseObject.new(:id, :word, :is_external, :is_phrase)
|
24
|
+
#
|
25
|
+
# #<struct Lymbix::Word id={:is_external=>false, :id=>34941, :word=>"demand"}, word=nil, is_external=nil>
|
26
|
+
#
|
27
|
+
# class Word
|
28
|
+
#
|
29
|
+
# def self.count
|
30
|
+
# resp = Lymbix::request('word_count')
|
31
|
+
# end
|
32
|
+
#
|
33
|
+
# def self.top_random
|
34
|
+
# resp = Lymbix::request('top_random')
|
35
|
+
# word = JSON.load(resp)
|
36
|
+
#
|
37
|
+
# return nil if word.nil? || word.empty?
|
38
|
+
# Word.new(word["id"], word["word"], word["is_external"], word["is_phrase"])
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# def self.add_word(word, definition, is_phrase = false)
|
42
|
+
# resp = Lymbix::request('words', 'post', {:word => word, :definition => definition, :is_external => true, :is_phrase => is_phrase})
|
43
|
+
# word = JSON.load(resp)
|
44
|
+
# return nil if word.nil? || word.empty?
|
45
|
+
# Word.new(word["id"], word["word"], word["is_external"], word["is_phrase"])
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# def self.lookup(word)
|
49
|
+
# resp = Lymbix::request("lookup/#{word}")
|
50
|
+
# return nil if resp == "null"
|
51
|
+
#
|
52
|
+
# word = JSON.load(resp)
|
53
|
+
#
|
54
|
+
# return nil if word.nil? || word.empty?
|
55
|
+
# Word.new(word["id"], word["word"], word["is_external"], word["is_phrase"])
|
56
|
+
# end
|
57
|
+
#
|
58
|
+
# def self.search(word)
|
59
|
+
# resp = Lymbix::request("search/#{word}")
|
60
|
+
# word = JSON.load(resp)
|
61
|
+
#
|
62
|
+
# return nil if word.nil? || word.empty?
|
63
|
+
# Word.new(word["id"], word["word"], word["is_external"], word["is_phrase"])
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# def self.find(word_id)
|
67
|
+
# resp = Lymbix::request("words/#{word_id}")
|
68
|
+
# word = JSON.load(resp)
|
69
|
+
#
|
70
|
+
# return nil if word.nil? || word.empty?
|
71
|
+
# Word.new(word["id"], word["word"], word["is_external"], word["is_phrase"])
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# def definitions
|
75
|
+
# Definition::list(self.id)
|
76
|
+
# end
|
77
|
+
#
|
78
|
+
# end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lymbix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 3
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Patrick Roy
|
13
|
+
- Josh Merchant
|
14
|
+
- Mathieu Dargavel
|
15
|
+
- "Matthew Lagac\xC3\xA9"
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2010-07-11 00:00:00 -03:00
|
21
|
+
default_executable:
|
22
|
+
dependencies: []
|
23
|
+
|
24
|
+
description: The Lymbix gem provides an interface to gyrus (connotative logic and database).
|
25
|
+
email: developers@lymbix.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
32
|
+
files:
|
33
|
+
- README
|
34
|
+
- Changelog
|
35
|
+
- LICENSE
|
36
|
+
- lib/lymbix.rb
|
37
|
+
- lib/lymbix/base.rb
|
38
|
+
- lib/lymbix/connotative_category.rb
|
39
|
+
- lib/lymbix/data_point.rb
|
40
|
+
- lib/lymbix/request.rb
|
41
|
+
- lib/lymbix/response.rb
|
42
|
+
- lib/lymbix/tweet.rb
|
43
|
+
- lib/lymbix/user.rb
|
44
|
+
- lib/lymbix/word.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://www.lymbix.com/
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.6
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: The Lymbix gem provides an interface to gyrus (connotative logic and database).
|
75
|
+
test_files: []
|
76
|
+
|