conversocial 0.0.6 → 0.0.7
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.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/lib/conversocial/resources/exceptions/base.rb +5 -3
- data/lib/conversocial/resources/exceptions/rate_limit_exceeded.rb +8 -0
- data/lib/conversocial/resources/models/base.rb +3 -4
- data/lib/conversocial/resources/models/keyvalue.rb +1 -3
- data/lib/conversocial/resources/models/report.rb +0 -2
- data/lib/conversocial/resources/models/tag.rb +0 -2
- data/lib/conversocial/resources/models/user.rb +0 -2
- data/lib/conversocial/resources/query_engines/base.rb +13 -28
- data/lib/conversocial/utils/http.rb +41 -0
- data/lib/conversocial/utils/strings.rb +16 -0
- data/lib/conversocial/version.rb +1 -1
- data/lib/conversocial.rb +5 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da63dfa82a8c5eea9d576e2b53aa4a49e4b1e6d9
|
4
|
+
data.tar.gz: 73121a7f101b21496f2a9619b90b82386ca610d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ef6fc9d185148037ad701a8921c87e10a31509cc91875d3c14cc055fb83033d38382a5920560278f543960fda751d6742b3f3a0eb2b2e7f2e96c12cfbb1fa69
|
7
|
+
data.tar.gz: 2ae5a97a6778e0d27dbbed132608efd9572b729d74a9526557acd72b89353044a81d06a12ac3c6490a296667eafc1555fb32009fb01213747ae3dca4bd7edd83
|
data/README.md
CHANGED
@@ -66,6 +66,9 @@ It is possible to chain filters
|
|
66
66
|
|
67
67
|
## Comparison Filters
|
68
68
|
|
69
|
+
#get all tags with id larger than 30000
|
70
|
+
client.tags.greater_than(:id, 30000).fetch
|
71
|
+
|
69
72
|
#get all conversations where oldest sort date is greater than or equal to today
|
70
73
|
client.conversations.greater_than_or_equal_to(:oldest_sort_date, Date.today ).fetch
|
71
74
|
|
@@ -78,6 +81,12 @@ It is possible to chain filters
|
|
78
81
|
#get all conversations where oldest sort date is lesser than today
|
79
82
|
client.conversations.lesser_than(:oldest_sort_date, Date.today ).fetch
|
80
83
|
|
84
|
+
#get all users where first name is nil
|
85
|
+
client.users.is_nil(:first_name).fetch
|
86
|
+
|
87
|
+
#get all users where first name is not nil
|
88
|
+
client.users.is_not_nil(:first_name).fetch
|
89
|
+
|
81
90
|
## Sorting
|
82
91
|
It is possible to sort your queries
|
83
92
|
|
@@ -119,7 +128,7 @@ To get all the conversations for today
|
|
119
128
|
conversations.each do |conversation|
|
120
129
|
puts "conversation #{conversation.id}"
|
121
130
|
conversation.contents.each do |content|
|
122
|
-
puts "#{content.author.real_name}: #{content.text}"
|
131
|
+
puts "#{content.author.try(:real_name)}: #{content.text}"
|
123
132
|
end
|
124
133
|
puts "\n"
|
125
134
|
end
|
@@ -2,9 +2,7 @@ module Conversocial
|
|
2
2
|
module Resources
|
3
3
|
module Exceptions
|
4
4
|
class Base < ::StandardError
|
5
|
-
|
6
5
|
attr_reader :status_code, :server_message, :application_message
|
7
|
-
attr_writer :default_message
|
8
6
|
|
9
7
|
def initialize(status_code = nil, server_message = nil, application_message = nil)
|
10
8
|
@status_code = status_code
|
@@ -13,7 +11,11 @@ module Conversocial
|
|
13
11
|
end
|
14
12
|
|
15
13
|
def to_s
|
16
|
-
|
14
|
+
lines = []
|
15
|
+
lines << "Status: #{status_code}" if status_code.present?
|
16
|
+
lines << "Server Message: #{server_message}" if server_message.present?
|
17
|
+
lines << "Application Message: #{application_message}" if application_message.present?
|
18
|
+
"\n" + lines.join("\n")
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -2,6 +2,8 @@ module Conversocial
|
|
2
2
|
module Resources
|
3
3
|
module Models
|
4
4
|
class Base
|
5
|
+
include Conversocial::Utils::Strings
|
6
|
+
|
5
7
|
attr_reader :loaded_attributes, :contents
|
6
8
|
|
7
9
|
def initialize params={}
|
@@ -65,6 +67,7 @@ module Conversocial
|
|
65
67
|
self
|
66
68
|
end
|
67
69
|
|
70
|
+
|
68
71
|
protected
|
69
72
|
|
70
73
|
def disable_association_resolving
|
@@ -121,8 +124,6 @@ module Conversocial
|
|
121
124
|
end
|
122
125
|
end
|
123
126
|
|
124
|
-
|
125
|
-
|
126
127
|
value
|
127
128
|
end
|
128
129
|
end
|
@@ -167,8 +168,6 @@ module Conversocial
|
|
167
168
|
def load_association value
|
168
169
|
client.send(pluralized_resource_type_from_association_attribute(value).to_sym).find value['id']
|
169
170
|
end
|
170
|
-
|
171
|
-
|
172
171
|
end
|
173
172
|
end
|
174
173
|
end
|
@@ -5,6 +5,8 @@ module Conversocial
|
|
5
5
|
module QueryEngines
|
6
6
|
class Base
|
7
7
|
include Enumerable
|
8
|
+
include Conversocial::Utils::Strings
|
9
|
+
include Conversocial::Utils::HTTP
|
8
10
|
|
9
11
|
attr_reader :client, :query_params
|
10
12
|
|
@@ -114,6 +116,14 @@ module Conversocial
|
|
114
116
|
comparison_filter field, "lte", value
|
115
117
|
end
|
116
118
|
|
119
|
+
def is_nil field
|
120
|
+
comparison_filter field, "isnull", 1
|
121
|
+
end
|
122
|
+
|
123
|
+
def is_not_nil field
|
124
|
+
comparison_filter field, "isnull", 0
|
125
|
+
end
|
126
|
+
|
117
127
|
def to_fetch_url
|
118
128
|
absolute_path add_query_params("", default_fetch_query_params.merge(@query_params))
|
119
129
|
end
|
@@ -153,8 +163,6 @@ module Conversocial
|
|
153
163
|
items
|
154
164
|
end
|
155
165
|
|
156
|
-
|
157
|
-
|
158
166
|
def resource_name
|
159
167
|
demodulize(model_klass.name).downcase
|
160
168
|
end
|
@@ -178,19 +186,13 @@ module Conversocial
|
|
178
186
|
def get_json path
|
179
187
|
#puts "getting json for #{absolute_path(path)}"
|
180
188
|
|
181
|
-
|
182
|
-
response = Net::HTTP.start(uri.host, uri.port,
|
183
|
-
:use_ssl => uri.scheme == 'https',
|
184
|
-
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
|
189
|
+
response = https_basic_auth_get client.key, client.secret, absolute_path(path)
|
185
190
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
http.request request # Net::HTTPResponse object
|
191
|
+
if 429 == response.code.to_i
|
192
|
+
raise Conversocial::Resources::Exceptions::RateLimitExceeded.new response.code, nil, response.body
|
190
193
|
end
|
191
194
|
|
192
195
|
json = JSON.parse response.body
|
193
|
-
|
194
196
|
if response.kind_of? Net::HTTPSuccess
|
195
197
|
json
|
196
198
|
else
|
@@ -206,23 +208,6 @@ module Conversocial
|
|
206
208
|
end
|
207
209
|
end
|
208
210
|
|
209
|
-
def add_query_params(url, params_to_add)
|
210
|
-
uri = URI url
|
211
|
-
params = (params_to_add || {}).merge URI.decode_www_form(uri.query.to_s).to_h
|
212
|
-
return url if params.blank?
|
213
|
-
uri.query = URI.encode_www_form(params)
|
214
|
-
uri.to_s
|
215
|
-
end
|
216
|
-
|
217
|
-
def demodulize(path)
|
218
|
-
path = path.to_s
|
219
|
-
if i = path.rindex('::')
|
220
|
-
path[(i+2)..-1]
|
221
|
-
else
|
222
|
-
path
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
211
|
def new params={}
|
227
212
|
new_instance_of_klass model_klass, params
|
228
213
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Utils
|
3
|
+
module HTTP
|
4
|
+
def https_basic_auth_get basic_auth_name, basic_auth_pass, url
|
5
|
+
uri = URI url
|
6
|
+
Net::HTTP.start(uri.host, uri.port,
|
7
|
+
:use_ssl => uri.scheme == 'https',
|
8
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
|
9
|
+
|
10
|
+
request = Net::HTTP::Get.new uri.request_uri
|
11
|
+
request.basic_auth basic_auth_name, basic_auth_pass
|
12
|
+
|
13
|
+
http.request request # Net::HTTPResponse object
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def https_basic_auth_post basic_auth_name, basic_auth_pass, url, post_params
|
18
|
+
uri = URI url
|
19
|
+
Net::HTTP.start(uri.host, uri.port,
|
20
|
+
:use_ssl => uri.scheme == 'https',
|
21
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
|
22
|
+
|
23
|
+
request = Net::HTTP::Post.new uri.request_uri
|
24
|
+
request.basic_auth basic_auth_name, basic_auth_pass
|
25
|
+
request.set_form_data post_params
|
26
|
+
|
27
|
+
http.request request # Net::HTTPResponse object
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def add_query_params(url, params_to_add)
|
33
|
+
uri = URI url
|
34
|
+
params = (params_to_add || {}).merge URI.decode_www_form(uri.query.to_s).to_h
|
35
|
+
return url if params.blank?
|
36
|
+
uri.query = URI.encode_www_form(params)
|
37
|
+
uri.to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/conversocial/version.rb
CHANGED
data/lib/conversocial.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require "conversocial/version"
|
2
2
|
require 'conversocial/client'
|
3
3
|
|
4
|
+
#require utils
|
5
|
+
require 'conversocial/utils/http'
|
6
|
+
require 'conversocial/utils/strings'
|
7
|
+
|
4
8
|
#require models
|
5
9
|
require 'conversocial/resources/models/base'
|
6
10
|
require 'conversocial/resources/models/account'
|
@@ -26,6 +30,7 @@ require 'conversocial/resources/query_engines/user'
|
|
26
30
|
|
27
31
|
#require exceptions
|
28
32
|
require 'conversocial/resources/exceptions/base'
|
33
|
+
require 'conversocial/resources/exceptions/rate_limit_exceeded'
|
29
34
|
|
30
35
|
module Conversocial
|
31
36
|
# Your code goes here...
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conversocial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Misha Conway
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/conversocial/client.rb
|
56
56
|
- lib/conversocial/resources.rb
|
57
57
|
- lib/conversocial/resources/exceptions/base.rb
|
58
|
+
- lib/conversocial/resources/exceptions/rate_limit_exceeded.rb
|
58
59
|
- lib/conversocial/resources/models.rb
|
59
60
|
- lib/conversocial/resources/models/account.rb
|
60
61
|
- lib/conversocial/resources/models/author.rb
|
@@ -76,6 +77,8 @@ files:
|
|
76
77
|
- lib/conversocial/resources/query_engines/report.rb
|
77
78
|
- lib/conversocial/resources/query_engines/tag.rb
|
78
79
|
- lib/conversocial/resources/query_engines/user.rb
|
80
|
+
- lib/conversocial/utils/http.rb
|
81
|
+
- lib/conversocial/utils/strings.rb
|
79
82
|
- lib/conversocial/version.rb
|
80
83
|
homepage: https://github.com/MishaConway/ruby-conversocial
|
81
84
|
licenses:
|