conversocial 0.0.4 → 0.0.5

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: ef8feb5467b16254c542a01b58fd1001df721499
4
- data.tar.gz: a1a4267eeb246cb6a1d6218173c1832fcbda5fe5
3
+ metadata.gz: 4ab11c32b300c1ed689033d453cd12f5adf2b878
4
+ data.tar.gz: ec30b42553642dc80875d15bb793bd9546694bcf
5
5
  SHA512:
6
- metadata.gz: c1f31b5dc24413551180556a05c390cc883463247d235d43ff81ba500e8504cbb266ff303bbddf798053a285090e295860426d62799d21cadf5728e5d017ebf4
7
- data.tar.gz: 1530913cc3cbbea2d7e72aa190aed25f04df0792ec6ff833b1a662b0d1ce030386073fb20c55cad4606613ae737c5595a673a04c58a443388ee51aa2fe4775bb
6
+ metadata.gz: ca7341f396e2cbe583cb948783880eb72b96035705c432c535809635a2696a5a00751a0b4e7be09381447795821675830d888590559da6f744b5def21460ef69
7
+ data.tar.gz: b4dde8d4c0429669fc3b724b2d3d819927edba1ff77ef5117ac9fc7dbc186cacbbcf84b3fb2257084e87848b04d53c5cff12c97752c9e9c408d0d8298fa915fd
data/lib/conversocial.rb CHANGED
@@ -6,6 +6,7 @@ require 'conversocial/resources/models/base'
6
6
  require 'conversocial/resources/models/account'
7
7
  require 'conversocial/resources/models/author'
8
8
  require 'conversocial/resources/models/channel'
9
+ require 'conversocial/resources/models/content'
9
10
  require 'conversocial/resources/models/conversation'
10
11
  require 'conversocial/resources/models/keyvalue'
11
12
  require 'conversocial/resources/models/report'
@@ -2,11 +2,12 @@ module Conversocial
2
2
  module Resources
3
3
  module Models
4
4
  class Base
5
- attr_reader :loaded_attributes
5
+ attr_reader :loaded_attributes, :contents
6
6
 
7
7
  def initialize params={}
8
8
  disable_association_resolving do
9
9
  @loaded_attributes = {}
10
+ @contents = []
10
11
  assign_attributes params
11
12
  end
12
13
  end
@@ -144,6 +145,10 @@ module Conversocial
144
145
  @query_engine = v
145
146
  end
146
147
 
148
+ def append_content content
149
+ @contents << content
150
+ end
151
+
147
152
  def association_attribute? attribute_value
148
153
  if attribute_value.kind_of? Hash
149
154
  return true if attribute_value['url'].present?
@@ -0,0 +1,16 @@
1
+ module Conversocial
2
+ module Resources
3
+ module Models
4
+ class Content < Base
5
+ def self.fields
6
+ %w{attachments parent author is_priority text tags sentiment channels platform link created_date type id is_private}
7
+ end
8
+ attributize_tags
9
+
10
+
11
+
12
+
13
+ end
14
+ end
15
+ end
16
+ end
@@ -13,9 +13,12 @@ author
13
13
  channels
14
14
  assigned_to
15
15
  content_ids
16
+ contents
16
17
  handling_times}.map &:to_sym
17
18
  end
18
19
 
20
+
21
+
19
22
  attributize_tags
20
23
 
21
24
 
@@ -60,20 +60,14 @@ module Conversocial
60
60
  self
61
61
  end
62
62
 
63
- def new params={}
64
- new_instance = model_klass.new params
65
- new_instance.send :assign_client, client
66
- new_instance.send :assign_query_engine, self
67
- new_instance
68
- end
69
-
70
63
  def find find_id
71
64
  @query_params[:fields] ||= model_klass.fields.join(',')
72
65
 
73
66
  json = get_json add_query_params("/#{find_id}", default_find_query_params.merge(@query_params))
74
67
  clear
75
68
  if json
76
- new json[resource_name]
69
+ item = new json[resource_name]
70
+ attach_content_to_items( [item], json['content']).first
77
71
  end
78
72
  end
79
73
 
@@ -135,13 +129,31 @@ module Conversocial
135
129
  clear
136
130
  items = []
137
131
  if json
132
+
133
+
138
134
  items = json[plural_resource_name].map do |instance_params|
139
135
  new instance_params
140
136
  end
137
+ items = attach_content_to_items items, json['content']
141
138
  end
142
139
  {:items => items, :json => json}
143
140
  end
144
141
 
142
+ def attach_content_to_items items, content_json_array
143
+ if content_json_array.present?
144
+ items.each do |item|
145
+ item.content_ids.each do |content_id|
146
+ content_json = content_json_array.find{ |ct| ct['id'] == content_id }
147
+ if content_json
148
+ item.send :append_content, new_instance_of_klass(Conversocial::Resources::Models::Content, content_json)
149
+ end
150
+ end
151
+ end
152
+ end
153
+ items
154
+ end
155
+
156
+
145
157
 
146
158
  def resource_name
147
159
  demodulize(model_klass.name).downcase
@@ -211,6 +223,17 @@ module Conversocial
211
223
  end
212
224
  end
213
225
 
226
+ def new params={}
227
+ new_instance_of_klass model_klass, params
228
+ end
229
+
230
+ def new_instance_of_klass klass, params
231
+ new_instance = klass.new params
232
+ new_instance.send :assign_client, client
233
+ new_instance.send :assign_query_engine, self
234
+ new_instance
235
+ end
236
+
214
237
  end
215
238
  end
216
239
  end
@@ -12,6 +12,10 @@ module Conversocial
12
12
  {:is_priority => false, :include => 'content'}
13
13
  end
14
14
 
15
+ def default_find_query_params
16
+ {:include => 'content'}
17
+ end
18
+
15
19
  def limit l
16
20
  where :page_size => l
17
21
  end
@@ -1,3 +1,3 @@
1
1
  module Conversocial
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conversocial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Misha Conway
@@ -60,6 +60,7 @@ files:
60
60
  - lib/conversocial/resources/models/author.rb
61
61
  - lib/conversocial/resources/models/base.rb
62
62
  - lib/conversocial/resources/models/channel.rb
63
+ - lib/conversocial/resources/models/content.rb
63
64
  - lib/conversocial/resources/models/conversation.rb
64
65
  - lib/conversocial/resources/models/keyvalue.rb
65
66
  - lib/conversocial/resources/models/report.rb