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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd5391669fb7b337fafadf1f2345946e680305ee
4
- data.tar.gz: 0f1aff374699fa9d68dec55eda315e0cadc88636
3
+ metadata.gz: da63dfa82a8c5eea9d576e2b53aa4a49e4b1e6d9
4
+ data.tar.gz: 73121a7f101b21496f2a9619b90b82386ca610d0
5
5
  SHA512:
6
- metadata.gz: 780aa670a939f2401b4aec2da2a78d06b07b6e8f555a162a60f4095e2b0e55d16a58670e9ce91d5335d9e4bc4f25bb5bc97ae256ed18bc17e463b4bec340f8ff
7
- data.tar.gz: 51afe9ebbb71953bae4b9806707d50f47450045b70ce3304efd52222b418fe58f5e27bbee7cc9d22fc58981301750c21d0e2b672b1b88e3e92aa283a02a2b9e4
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
- "\nStatus: #{status_code}\nServer Message: #{server_message}\nApplication Message: #{application_message}"
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
@@ -0,0 +1,8 @@
1
+ module Conversocial
2
+ module Resources
3
+ module Exceptions
4
+ class RateLimitExceeded < Base
5
+ end
6
+ end
7
+ end
8
+ 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
@@ -3,12 +3,10 @@ module Conversocial
3
3
  module Models
4
4
  class Keyvalue < Base
5
5
  def self.fields
6
- %w{}
6
+ %w{key value value_type}
7
7
  end
8
8
 
9
9
  attributize_tags
10
-
11
-
12
10
  end
13
11
  end
14
12
  end
@@ -7,8 +7,6 @@ module Conversocial
7
7
  end
8
8
 
9
9
  attributize_tags
10
-
11
-
12
10
  end
13
11
  end
14
12
  end
@@ -7,8 +7,6 @@ module Conversocial
7
7
  end
8
8
 
9
9
  attributize_tags
10
-
11
-
12
10
  end
13
11
  end
14
12
  end
@@ -7,8 +7,6 @@ module Conversocial
7
7
  end
8
8
 
9
9
  attributize_tags
10
-
11
-
12
10
  end
13
11
  end
14
12
  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
- uri = URI absolute_path(path)
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
- request = Net::HTTP::Get.new uri.request_uri
187
- request.basic_auth client.key, client.secret
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
@@ -0,0 +1,16 @@
1
+ module Conversocial
2
+ module Utils
3
+ module Strings
4
+
5
+
6
+ def demodulize(path)
7
+ path = path.to_s
8
+ if i = path.rindex('::')
9
+ path[(i+2)..-1]
10
+ else
11
+ path
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Conversocial
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
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.6
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-09-30 00:00:00.000000000 Z
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: