lymbix 0.3.7 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Changelog +1 -0
- data/lib/lymbix.rb +1 -6
- data/lib/lymbix/base.rb +59 -235
- data/lib/lymbix/request.rb +4 -22
- data/lib/lymbix/response.rb +2 -2
- metadata +5 -10
- data/lib/lymbix/connotative_category.rb +0 -15
- data/lib/lymbix/data_point.rb +0 -61
- data/lib/lymbix/tweet.rb +0 -15
- data/lib/lymbix/user.rb +0 -98
- data/lib/lymbix/word.rb +0 -78
data/Changelog
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
v0.4.0 - re-factored whole gem, implemented methods for 2.1 version
|
1
2
|
v0.3.7 - added endpoint attribute to Base for companies implementation
|
2
3
|
v0.3.6 - added end and start time to data points coming from toneaday
|
3
4
|
v.0.3.5 - added tonalize_article, tonalize_paragraph which belongs to the 2.0 version of gyrus, also modified the request to include the version header
|
data/lib/lymbix.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
2
2
|
|
3
3
|
require 'lymbix/configuration'
|
4
|
-
require 'lymbix/user'
|
5
4
|
require 'lymbix/request'
|
6
5
|
require 'lymbix/response'
|
7
|
-
require 'lymbix/
|
8
|
-
require 'lymbix/base'
|
9
|
-
require 'lymbix/connotative_category'
|
10
|
-
require 'lymbix/tweet'
|
11
|
-
require 'lymbix/data_point'
|
6
|
+
require 'lymbix/base'
|
data/lib/lymbix/base.rb
CHANGED
@@ -1,261 +1,85 @@
|
|
1
1
|
module Lymbix
|
2
2
|
|
3
|
+
=begin rdoc
|
4
|
+
The Base class is the most used class in the Lymbix gem.
|
5
|
+
It incorporates all the methods used to tonalize.
|
6
|
+
|
7
|
+
To begin using the base class, you must authenticate using one of the authenticate methods and store the results in a variable.
|
8
|
+
On a successful authentication, you can start calling tonalize methods immediatly.
|
9
|
+
=end
|
10
|
+
|
3
11
|
class Base
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@app_id = options[:app_id]
|
10
|
-
@lymbix_user_id = options[:lymbix_user_id]
|
11
|
-
@endpoint = options[:endpoint]
|
12
|
-
@user = User.new(options[:user].merge({:auth_key => options[:auth_key]})) if options[:user]
|
13
|
-
if @user
|
14
|
-
@lymbix_user_id = @user.lymbix_user_id
|
15
|
-
end
|
16
|
-
else
|
17
|
-
@error_messages = options[:error_messages]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def open_bar_auth_key(options)
|
22
|
-
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
|
23
|
-
response.data["auth_key"]
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.authenticate(email, password, app_id)
|
27
|
-
response = Lymbix::Request.new(:post, 'authenticate', {:app_id => app_id}, {:app_id => app_id, :email => email, :password => password}).run
|
28
|
-
hash_response = response.data.to_hash
|
29
|
-
self.new(:auth_key => hash_response["auth_key"], :app_id => app_id, :endpoint => hash_response["endpoint"], :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 => []})
|
30
|
-
rescue RestClient::Unauthorized
|
31
|
-
self.new(:error_messages => "Wrong Password")
|
32
|
-
rescue Exception => ex
|
33
|
-
self.new(:error_messages => "#{ex.message} \n #{ex.backtrace}")
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.authenticate_from_auth_and_id(lymbix_user_id, auth_key, app_id)
|
37
|
-
ActiveRecord::Base.logger.info "self.authenticate_from_auth_and_id"
|
38
|
-
|
39
|
-
response = Lymbix::Request.new(:post, 'authenticate_from_auth_and_id', {:app_id => app_id}, {:app_id => app_id, :lymbix_user_id => lymbix_user_id, :auth_key => auth_key}).run
|
40
|
-
hash_response = response.data.to_hash
|
41
|
-
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 => []})
|
42
|
-
rescue Exception => ex
|
43
|
-
self.new(:error_messages => "#{ex.message} \n #{ex.backtrace}")
|
44
|
-
end
|
45
|
-
|
46
|
-
def service_up
|
47
|
-
response = request(:get, 'service_up').data
|
48
|
-
end
|
49
|
-
|
50
|
-
def word_count
|
51
|
-
response = request(:get, 'word_count').data
|
52
|
-
response["count"].to_i
|
53
|
-
end
|
54
|
-
|
55
|
-
def contribution_count
|
56
|
-
response = request(:get, 'contribution_count').data
|
57
|
-
response["contribution_count"].to_i
|
58
|
-
end
|
59
|
-
|
60
|
-
def toneaday_daily_best
|
61
|
-
response = request(:get, 'toneaday_daily_best').data
|
62
|
-
puts response["daily_toneaday_user_id"].to_i
|
63
|
-
[response["daily_toneaday_user_id"].to_i, response["daily_toneaday_contribution_count"].to_i]
|
64
|
-
end
|
65
|
-
|
66
|
-
def toneaday_weekly_best
|
67
|
-
response = request(:get, 'toneaday_weekly_best').data
|
68
|
-
[response["weekly_toneaday_user_id"].to_i, response["weekly_toneaday_contribution_count"].to_i]
|
69
|
-
end
|
70
|
-
|
71
|
-
def user_contribution_count(user_id)
|
72
|
-
response = request(:get, "contribution_count/#{user_id}").data
|
73
|
-
response["contribution_count"].to_i
|
74
|
-
end
|
75
|
-
|
76
|
-
def tonalized_words_count
|
77
|
-
response = request(:get, 'tonalized_words').data
|
78
|
-
response["tonalized_words_count"].to_i
|
79
|
-
end
|
12
|
+
# The user's authentication key
|
13
|
+
attr_accessor :auth_key
|
14
|
+
# Error messages that were caught during the authentication
|
15
|
+
attr_accessor :error_messages
|
16
|
+
# API Version
|
80
17
|
|
81
|
-
def
|
82
|
-
|
83
|
-
Word.new(:id => response.data["id"], :word => response.data["word"], :is_external => response.data["is_external"], :is_phrase => response.data["is_phrase"])
|
18
|
+
def initialize(auth_key)
|
19
|
+
@auth_key = auth_key
|
84
20
|
end
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
21
|
+
|
22
|
+
# Tonalizes text using version 2.1 of ToneAPI
|
23
|
+
def tonalize(article, return_fields = [], accept_type = "application/json")
|
24
|
+
@version = 2.1
|
25
|
+
accept_type == "application/xml" ? return_fields = return_fields_xml(return_fields) : return_fields = return_fields_json(return_fields)
|
26
|
+
response = request(:post, 'tonalize',{:article => article, :return_fields => return_fields}, {:accept => accept_type}).data
|
89
27
|
end
|
90
28
|
|
91
|
-
|
92
|
-
def
|
93
|
-
|
94
|
-
|
95
|
-
Word.new(:id => response.data["id"], :word => response.data["word"], :is_external => response.data["is_external"], :is_phrase => response.data["is_phrase"])
|
96
|
-
else
|
97
|
-
nil
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def add_word(word, definition, is_phrase = false)
|
102
|
-
ActiveRecord::Base.logger.info "ADD_WORD START"
|
103
|
-
response = request(:post, 'words', {:word => word, :definition => definition, :is_external => true, :is_phrase => is_phrase})
|
104
|
-
ActiveRecord::Base.logger.info "ADD_WORD END #{response.inspect}"
|
105
|
-
Word.new(:id => response.data["id"], :word => response.data["word"], :is_external => response.data["is_external"], :is_phrase => response.data["is_phrase"])
|
106
|
-
end
|
107
|
-
|
108
|
-
def bad_ratings_count(user_id,last_checkout_date)
|
109
|
-
response = request(:get, "bad_ratings_count/#{user_id}/#{last_checkout_date}")
|
110
|
-
end
|
111
|
-
|
112
|
-
def expunge(word)
|
113
|
-
response = request(:post,'expunge', {:word => word})
|
114
|
-
end
|
115
|
-
|
116
|
-
# MODERATION
|
117
|
-
|
118
|
-
def approve_tonecheck_beta(user_id)
|
119
|
-
response = request(:post, 'approve_tonecheck_beta', {:user_id => user_id})
|
29
|
+
# Tonalizes text using version 2.0 of ToneAPI
|
30
|
+
def tonalize_article(article, accept_type = "application/json")
|
31
|
+
@version = 2.0
|
32
|
+
response = request(:post, 'tonalize_article',{:article => article}, {:accept => accept_type}).data
|
120
33
|
end
|
121
34
|
|
122
|
-
|
123
|
-
|
35
|
+
# Tonalizes mutliple articles using version 2.1 of ToneAPI. With the return_fields param you can now specify which field to get back from the API.
|
36
|
+
def tonalize_multiple(articles, return_fields = [], accept_type = "application/json")
|
37
|
+
@version = 2.1
|
38
|
+
accept_type == "application/xml" ? return_fields = return_fields_xml(return_fields) : return_fields = return_fields_json(return_fields)
|
39
|
+
accept_type == "application/xml" ? articles = articles_xml(articles) : articles = articles_json(articles)
|
40
|
+
response = request(:post, 'tonalize_multiple',{:articles => articles, :return_fields => return_fields}, {:accept => accept_type}).data
|
124
41
|
end
|
125
42
|
|
126
|
-
|
127
|
-
|
128
|
-
|
43
|
+
# Tonalizes article using version 2.1 of ToneAPI. With the return_fields param you can now specify which field to get back from the API.
|
44
|
+
# The detailed response includes the tonalization data for the article and all sentences found in the article
|
45
|
+
def tonalize_detailed(article, return_fields = [], accept_type = "application/json")
|
46
|
+
@version = 2.1
|
47
|
+
accept_type == "application/xml" ? return_fields = return_fields_xml(return_fields) : return_fields = return_fields_json(return_fields)
|
48
|
+
response = request(:post, 'tonalize_detailed',{:article => article, :return_fields => return_fields}, {:accept => accept_type}).data
|
129
49
|
end
|
130
50
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
def moderated_count
|
137
|
-
response = request(:get, 'moderated_count', {:app_id => @app_id})
|
138
|
-
response.data['moderated_count']
|
139
|
-
end
|
51
|
+
# Flags a phrase to be re-evaluated
|
52
|
+
def flag_response(phrase, api_method_requested, api_version, callback_url = nil)
|
53
|
+
@version = 2.1
|
54
|
+
response = request(:post, 'flag_response', {:phrase => phrase, :api_method_requested => api_method_requested, :api_version => api_version, :callback_url => callback_url}).data
|
55
|
+
end
|
140
56
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
def moderated
|
147
|
-
response = request(:get, 'moderated', {:app_id => @app_id})
|
148
|
-
response.data['moderated']
|
149
|
-
end
|
150
|
-
|
151
|
-
def unmoderated
|
152
|
-
response = request(:get, 'unmoderated', {:app_id => @app_id})
|
153
|
-
response.data['unmoderated']
|
154
|
-
end
|
155
|
-
|
156
|
-
def user_data_points(user_id, page = 1, earnings_in_cents = 0)
|
157
|
-
response = request(:get, "user_data_points/#{user_id}/#{page}/#{earnings_in_cents}", {:app_id => @app_id})
|
158
|
-
response.data['data']
|
159
|
-
end
|
160
|
-
|
161
|
-
def medulla_data_points(phrase)
|
162
|
-
response = request(:get, "medulla_data_points", {:app_id => @app_id, :phrase => phrase})
|
163
|
-
ActiveRecord::Base.logger.info "!!! medulla_data_points #{response.data['data']}"
|
164
|
-
response.data['data']
|
165
|
-
end
|
166
|
-
|
167
|
-
def user_search(query)
|
168
|
-
response = request(:post, "user_search", {:app_id => @app_id, :query => query})
|
169
|
-
response.data['users']
|
170
|
-
end
|
171
|
-
|
172
|
-
def find_user_by_id(user_id)
|
173
|
-
response = request(:post, "find_user_by_id", {:app_id => @app_id, :user_id => user_id})
|
174
|
-
response.data['user']
|
175
|
-
end
|
176
|
-
|
177
|
-
def find_users_by_ids(user_ids)
|
178
|
-
response = request(:post, "find_users_by_ids", {:app_id => @app_id, :user_ids => user_ids.join(',')})
|
179
|
-
response.data['users']
|
180
|
-
end
|
181
|
-
|
182
|
-
def archive_user_data(user_id)
|
183
|
-
response = request(:post, "archive_user_data/#{user_id}", {:app_id => @app_id})
|
184
|
-
response
|
185
|
-
end
|
186
|
-
|
187
|
-
# END
|
188
|
-
|
189
|
-
def word_data(phrase)
|
190
|
-
response = request(:post, 'word_data', {:phrase => phrase}).data
|
191
|
-
end
|
192
|
-
|
193
|
-
# def update_user_app_config(user_app_config_xml)
|
194
|
-
# response = request(:post, 'update_user_app_config', {:user_app_config => user_app_config_xml},{:version => 2}).data
|
195
|
-
# end
|
196
|
-
|
197
|
-
# def checksum_user_app_config(checksum)
|
198
|
-
# response = request(:post, 'checksum_user_app_config',{:checksum_user_app_config => checksum},{:version => 2}).data
|
199
|
-
# end
|
200
|
-
|
201
|
-
def tonalize_words(phrase)
|
202
|
-
response = request(:post, 'tonalize_words', {:phrase => phrase}).data
|
203
|
-
end
|
204
|
-
|
205
|
-
def tonalize_paragraph(paragraph)
|
206
|
-
response = request(:post, 'tonalize_paragraph', {:paragraph => paragraph}, {:version => 2}).data
|
207
|
-
end
|
208
|
-
|
209
|
-
def tone_alternates(phrase)
|
210
|
-
response = request(:post, 'suggestions',{:phrase => phrase}).data
|
211
|
-
end
|
212
|
-
|
213
|
-
def suggest_alternates(phrase,alternates)
|
214
|
-
response = request(:post, 'suggest_alternates',{:phrase => phrase, :alternates => alternates}).data
|
215
|
-
end
|
216
|
-
|
217
|
-
def tonalize_article(article)
|
218
|
-
response = request(:post, 'tonalize_article',{:article => article},{:version => 2}).data
|
219
|
-
end
|
220
|
-
|
221
|
-
def all_connotative_categories
|
222
|
-
response = request(:get, 'connotative_categories')
|
223
|
-
all_cc = []
|
224
|
-
response.data.each do |cc|
|
225
|
-
all_cc << ConnotativeCategory.new(:id => cc["id"], :name => cc["name"], :is_positive => cc["is_positive"])
|
226
|
-
end
|
227
|
-
all_cc
|
228
|
-
end
|
229
|
-
|
230
|
-
def top_tweet
|
231
|
-
response = request(:get, 'top_tweet').data
|
232
|
-
tweet = Tweet.new(:id => response["id"], :is_user_created => response["is_user_created"], :tweet => response["tweet"], :requested_count => response["requested_count"])
|
233
|
-
tweet.instance_variable_set(:@phrases_found,response["phrases_found"])
|
234
|
-
return tweet
|
57
|
+
private
|
58
|
+
def request(action, method, data, headers = {})
|
59
|
+
Lymbix::Request.new(action, method, {:app_id => @app_id, :auth_key => @auth_key, :version => @version, :accept_type => headers[:accept]}, data).run
|
235
60
|
end
|
236
61
|
|
237
|
-
def
|
238
|
-
|
62
|
+
def return_fields_xml(return_fields)
|
63
|
+
xml = "<return_fields>"
|
64
|
+
return_fields.each {|field| xml << "<field>" + field + "</field>"}
|
65
|
+
xml << "</return_fields>"
|
66
|
+
xml
|
239
67
|
end
|
240
68
|
|
241
|
-
def
|
242
|
-
|
69
|
+
def return_fields_json(return_fields)
|
70
|
+
return_fields.to_json
|
243
71
|
end
|
244
72
|
|
245
|
-
def
|
246
|
-
|
247
|
-
|
73
|
+
def articles_xml(articles)
|
74
|
+
xml = "<articles>"
|
75
|
+
articles.each {|article| xml << "<article>" + article + "</article>"}
|
76
|
+
xml << "</articles>"
|
77
|
+
xml
|
248
78
|
end
|
249
79
|
|
250
|
-
|
251
|
-
|
252
|
-
if headers
|
253
|
-
Lymbix::Request.new(action, method, {:app_id => @app_id, :auth_key => @auth_key, :lymbix_user_id => @lymbix_user_id, :version => headers[:version]}, data).run
|
254
|
-
else
|
255
|
-
Lymbix::Request.new(action, method, {:app_id => @app_id, :auth_key => @auth_key, :lymbix_user_id => @lymbix_user_id, :version => 1}, data).run
|
256
|
-
end
|
80
|
+
def articles_json(articles)
|
81
|
+
articles.to_json
|
257
82
|
end
|
258
|
-
|
259
83
|
end
|
260
84
|
|
261
85
|
end
|
data/lib/lymbix/request.rb
CHANGED
@@ -15,7 +15,7 @@ module Lymbix
|
|
15
15
|
|
16
16
|
def connection
|
17
17
|
options = {}
|
18
|
-
options[:headers] = {:accept =>
|
18
|
+
options[:headers] = {:accept => self.header_hash[:accept_type], :AUTHENTICATION => self.header_hash[:auth_key], :VERSION => self.header_hash[:version]}
|
19
19
|
RestClient::Resource.new(self.url, options)
|
20
20
|
end
|
21
21
|
|
@@ -23,32 +23,14 @@ module Lymbix
|
|
23
23
|
case(self.http_method)
|
24
24
|
when :get
|
25
25
|
self.connection[self.method].get do |resp|
|
26
|
-
|
27
|
-
case resp.code
|
28
|
-
when 200
|
29
|
-
self.response = resp.body
|
30
|
-
when 401
|
31
|
-
raise RestClient::Unauthorized
|
32
|
-
end
|
33
|
-
rescue
|
34
|
-
puts resp.inspect
|
35
|
-
end
|
26
|
+
self.response = resp.body
|
36
27
|
end
|
37
28
|
when :post
|
38
29
|
self.connection[self.method].post(object) do |resp|
|
39
|
-
|
40
|
-
case resp.code
|
41
|
-
when 200
|
42
|
-
self.response = resp.body
|
43
|
-
when 401
|
44
|
-
raise RestClient::Unauthorized
|
45
|
-
end
|
46
|
-
rescue
|
47
|
-
puts resp.inspect
|
48
|
-
end
|
30
|
+
self.response = resp.body
|
49
31
|
end
|
50
32
|
end
|
51
33
|
Response.new(self.response)
|
52
34
|
end
|
53
35
|
end
|
54
|
-
end
|
36
|
+
end
|
data/lib/lymbix/response.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lymbix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Patrick Roy
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2010-
|
21
|
+
date: 2010-12-17 00:00:00 -04:00
|
22
22
|
default_executable:
|
23
23
|
dependencies: []
|
24
24
|
|
@@ -37,13 +37,8 @@ files:
|
|
37
37
|
- lib/lymbix/configuration.rb
|
38
38
|
- lib/lymbix.rb
|
39
39
|
- lib/lymbix/base.rb
|
40
|
-
- lib/lymbix/connotative_category.rb
|
41
|
-
- lib/lymbix/data_point.rb
|
42
40
|
- lib/lymbix/request.rb
|
43
41
|
- lib/lymbix/response.rb
|
44
|
-
- lib/lymbix/tweet.rb
|
45
|
-
- lib/lymbix/user.rb
|
46
|
-
- lib/lymbix/word.rb
|
47
42
|
has_rdoc: true
|
48
43
|
homepage: http://www.lymbix.com/
|
49
44
|
licenses: []
|
data/lib/lymbix/data_point.rb
DELETED
@@ -1,61 +0,0 @@
|
|
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], :start_rate_time => data[:start_rate_time], :end_rate_time => data[:end_rate_time], :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
|
data/lib/lymbix/tweet.rb
DELETED
@@ -1,15 +0,0 @@
|
|
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
DELETED
@@ -1,98 +0,0 @@
|
|
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
|
-
ActiveRecord::Base.logger.info "!!! self.authenticate response.inspect"
|
34
|
-
self.new(response.data.to_hash)
|
35
|
-
rescue RestClient::Unauthorized
|
36
|
-
self.new(:error_messages => ["Wrong Password"])
|
37
|
-
rescue Exception => ex
|
38
|
-
self.new(:error_messages => ["#{ex.message}"])
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.enable_application(params)
|
42
|
-
begin
|
43
|
-
response = Lymbix::Request.new(:post, 'enable_application', {:app_id => params[:app_id]}, {:email => params[:email], :password => params[:password]}).run
|
44
|
-
self.new(response.data.to_hash)
|
45
|
-
rescue Exception => ex
|
46
|
-
self.new(:error_messages => [ex.message])
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.find_by_email(params)
|
51
|
-
ActiveRecord::Base.logger.info "!!! self.find_by_email(params) #{params[:email]}"
|
52
|
-
begin
|
53
|
-
response = Lymbix::Request.new(:post, 'user_find_by_email', {:app_id => params[:app_id]}, {:email => params[:email]}).run
|
54
|
-
self.new(response.data.to_hash)
|
55
|
-
rescue Exception => ex
|
56
|
-
self.new(:error_messages => [ex.message])
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.find_or_create(params)
|
61
|
-
|
62
|
-
begin
|
63
|
-
# 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
|
64
|
-
response = Lymbix::Request.new(:post, 'find_user', {:app_id => params[:app_id]}, {:email => params[:user][:email]}).run
|
65
|
-
|
66
|
-
ActiveRecord::Base.logger.info "!! REQUEST DONE - #{response.inspect}"
|
67
|
-
|
68
|
-
unless response.data["email"]
|
69
|
-
response = Lymbix::Request.new(:post, 'users', {:app_id => params[:app_id]}, params[:user]).run #unless response.data['auth_key']
|
70
|
-
if response.data["error_messages"]
|
71
|
-
return self.new(:error_messages => response.data["error_messages"])
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
self.new(response.data.to_hash)
|
76
|
-
rescue Exception => ex
|
77
|
-
ActiveRecord::Base.logger.info "!! REQUEST FAIL - #{ex.message}"
|
78
|
-
|
79
|
-
self.new(:error_messages => [ex.message])
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def self.update(params)
|
84
|
-
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
|
85
|
-
if response.success
|
86
|
-
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 => [])
|
87
|
-
else
|
88
|
-
self.new(:error_messages => response.data.errors)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def self.request_tonecheck_beta(params)
|
93
|
-
response = Lymbix::Request.new(:post, 'request_tonecheck_beta', {:app_id => params[:app_id], :auth_key => params[:auth_key]}, {:user_id => params[:user_id]}).run
|
94
|
-
response.data['user']
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
data/lib/lymbix/word.rb
DELETED
@@ -1,78 +0,0 @@
|
|
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
|