conversocial 0.0.2
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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/conversocial.gemspec +23 -0
- data/lib/conversocial.rb +31 -0
- data/lib/conversocial/client.rb +45 -0
- data/lib/conversocial/resources.rb +13 -0
- data/lib/conversocial/resources/exceptions/base.rb +21 -0
- data/lib/conversocial/resources/models.rb +13 -0
- data/lib/conversocial/resources/models/account.rb +15 -0
- data/lib/conversocial/resources/models/author.rb +13 -0
- data/lib/conversocial/resources/models/base.rb +170 -0
- data/lib/conversocial/resources/models/channel.rb +13 -0
- data/lib/conversocial/resources/models/conversation.rb +29 -0
- data/lib/conversocial/resources/models/keyvalue.rb +15 -0
- data/lib/conversocial/resources/models/report.rb +15 -0
- data/lib/conversocial/resources/models/tag.rb +15 -0
- data/lib/conversocial/resources/models/user.rb +15 -0
- data/lib/conversocial/resources/query_engines.rb +13 -0
- data/lib/conversocial/resources/query_engines/account.rb +22 -0
- data/lib/conversocial/resources/query_engines/author.rb +20 -0
- data/lib/conversocial/resources/query_engines/base.rb +181 -0
- data/lib/conversocial/resources/query_engines/channel.rb +18 -0
- data/lib/conversocial/resources/query_engines/conversation.rb +27 -0
- data/lib/conversocial/resources/query_engines/keyvalue.rb +19 -0
- data/lib/conversocial/resources/query_engines/report.rb +19 -0
- data/lib/conversocial/resources/query_engines/tag.rb +19 -0
- data/lib/conversocial/resources/query_engines/user.rb +19 -0
- data/lib/conversocial/version.rb +3 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c43003f6dc1bf8accf333960ecf3b2007067ff1
|
4
|
+
data.tar.gz: 84a988b6866afacbac1f41f48c74d986b6bb4cb3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c108a618244ce1790d069d3875b560662c260eff7078c1c9f4e15495cef27efdd50e18ddb5e42dff38ff1ba3b2850fefecd5ab13f640e71487611d50ce742da
|
7
|
+
data.tar.gz: 1fa44ea6c3e921cab7b6a46422c49126904da39f94822a78b79169d8b5c2b1503e539ae14f23dfaccbf5cf1412d05c44592063b297eec6ae7c0892f349853dc3
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Misha Conway
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Conversocial
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'conversocial'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install conversocial
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/conversocial/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'conversocial/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "conversocial"
|
8
|
+
spec.version = Conversocial::VERSION
|
9
|
+
spec.authors = ["Misha Conway"]
|
10
|
+
spec.email = ["mishaAconway@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby gem that wraps the conversocial api in an ORM pattern}
|
12
|
+
spec.description = %q{Ruby gem that wraps the conversocial api in an ORM pattern}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/conversocial.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "conversocial/version"
|
2
|
+
require 'conversocial/client'
|
3
|
+
|
4
|
+
#require models
|
5
|
+
require 'conversocial/resources/models/base'
|
6
|
+
require 'conversocial/resources/models/account'
|
7
|
+
require 'conversocial/resources/models/author'
|
8
|
+
require 'conversocial/resources/models/channel'
|
9
|
+
require 'conversocial/resources/models/conversation'
|
10
|
+
require 'conversocial/resources/models/keyvalue'
|
11
|
+
require 'conversocial/resources/models/report'
|
12
|
+
require 'conversocial/resources/models/tag'
|
13
|
+
require 'conversocial/resources/models/user'
|
14
|
+
|
15
|
+
#require query engines
|
16
|
+
require 'conversocial/resources/query_engines/base'
|
17
|
+
require 'conversocial/resources/query_engines/account'
|
18
|
+
require 'conversocial/resources/query_engines/author'
|
19
|
+
require 'conversocial/resources/query_engines/channel'
|
20
|
+
require 'conversocial/resources/query_engines/conversation'
|
21
|
+
require 'conversocial/resources/query_engines/keyvalue'
|
22
|
+
require 'conversocial/resources/query_engines/report'
|
23
|
+
require 'conversocial/resources/query_engines/tag'
|
24
|
+
require 'conversocial/resources/query_engines/user'
|
25
|
+
|
26
|
+
#require exceptions
|
27
|
+
require 'conversocial/resources/exceptions/base'
|
28
|
+
|
29
|
+
module Conversocial
|
30
|
+
# Your code goes here...
|
31
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Conversocial
|
2
|
+
class Client
|
3
|
+
attr_reader :version, :key, :secret
|
4
|
+
|
5
|
+
|
6
|
+
def initialize options={}
|
7
|
+
@key = options[:key]
|
8
|
+
@secret = options[:secret]
|
9
|
+
@version = options[:version]
|
10
|
+
end
|
11
|
+
|
12
|
+
def accounts
|
13
|
+
(@accounts ||= Conversocial::Resources::QueryEngines::Account.new self).clear
|
14
|
+
end
|
15
|
+
|
16
|
+
def authors
|
17
|
+
(@authors ||= Conversocial::Resources::QueryEngines::Author.new self).clear
|
18
|
+
end
|
19
|
+
|
20
|
+
def channels
|
21
|
+
(@channels ||= Conversocial::Resources::QueryEngines::Channel.new self).clear
|
22
|
+
end
|
23
|
+
|
24
|
+
#TODO: implement keyvalues support
|
25
|
+
#def keyvalues
|
26
|
+
# (@keyvalues ||= Conversocial::Resources::QueryEngines::Keyvalue.new self).clear
|
27
|
+
#end
|
28
|
+
|
29
|
+
def reports
|
30
|
+
(@reports ||= Conversocial::Resources::QueryEngines::Report.new self).clear
|
31
|
+
end
|
32
|
+
|
33
|
+
def tags
|
34
|
+
(@tags ||= Conversocial::Resources::QueryEngines::Tag.new self).clear
|
35
|
+
end
|
36
|
+
|
37
|
+
def users
|
38
|
+
(@users ||= Conversocial::Resources::QueryEngines::User.new self).clear
|
39
|
+
end
|
40
|
+
|
41
|
+
def conversations
|
42
|
+
(@conversations ||= Conversocial::Resources::QueryEngines::Conversation.new self).clear
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module Exceptions
|
4
|
+
class Base < ::StandardError
|
5
|
+
|
6
|
+
attr_reader :status_code, :server_message, :application_message
|
7
|
+
attr_writer :default_message
|
8
|
+
|
9
|
+
def initialize(status_code = nil, server_message = nil, application_message = nil)
|
10
|
+
@status_code = status_code
|
11
|
+
@server_message = server_message
|
12
|
+
@application_message = application_message
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
"\nStatus: #{status_code}\nServer Message: #{server_message}\nApplication Message: #{application_message}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module Models
|
4
|
+
class Author < Base
|
5
|
+
def self.fields
|
6
|
+
%w{id url platform platform_id screen_name real_name location website description profile_picture profile_link}
|
7
|
+
end
|
8
|
+
attributize_tags
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module Models
|
4
|
+
class Base
|
5
|
+
attr_reader :loaded_attributes
|
6
|
+
|
7
|
+
def initialize params={}
|
8
|
+
disable_association_resolving do
|
9
|
+
@loaded_attributes = {}
|
10
|
+
assign_attributes params
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def inspect
|
15
|
+
attr_list = attributes.map { |k,v| "#{k}: #{v}" } * ', '
|
16
|
+
"#<#{self.class.name}(#{attr_list})>"
|
17
|
+
end
|
18
|
+
|
19
|
+
def assign_attributes params={}
|
20
|
+
params.each do |k, v|
|
21
|
+
send "#{k}=".to_sym, v
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def fields
|
26
|
+
self.class.fields
|
27
|
+
end
|
28
|
+
|
29
|
+
def attributes mark_not_yet_loaded=true
|
30
|
+
inspect_unloaded_association = ->(v) do
|
31
|
+
"#<#{singularized_resource_type_from_association_attribute(v).capitalize}(id: #{v['id']})>"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
attrs = nil
|
36
|
+
disable_association_resolving do
|
37
|
+
attrs = self.class.fields.map do |field_name|
|
38
|
+
val = send(field_name.to_sym)
|
39
|
+
if mark_not_yet_loaded
|
40
|
+
if val.nil? && @loaded_attributes[field_name.to_sym].nil?
|
41
|
+
val = :not_yet_loaded
|
42
|
+
elsif association_attribute? val
|
43
|
+
val = inspect_unloaded_association.call val
|
44
|
+
elsif val.kind_of? Array
|
45
|
+
val = val.map do |v|
|
46
|
+
if association_attribute? v
|
47
|
+
inspect_unloaded_association.call v
|
48
|
+
else
|
49
|
+
v
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
[field_name, val]
|
55
|
+
end.to_h
|
56
|
+
end
|
57
|
+
attrs
|
58
|
+
end
|
59
|
+
|
60
|
+
def refresh
|
61
|
+
disable_association_resolving do
|
62
|
+
assign_attributes query_engine.find(id).attributes(false)
|
63
|
+
end
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def disable_association_resolving
|
70
|
+
@disable_association_resolving = true
|
71
|
+
yield
|
72
|
+
@disable_association_resolving = false
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.attributize_tags
|
76
|
+
fields.map(&:to_sym).each do |f|
|
77
|
+
|
78
|
+
define_method "#{f}=".to_sym do |v|
|
79
|
+
@loaded_attributes[f] = 1
|
80
|
+
|
81
|
+
#if date or time attribute and value is a string parse as time
|
82
|
+
if v.kind_of?(String)
|
83
|
+
if %w{created date_to date_from date_joined last_login}.include?(f.to_s) || f.to_s.match(/date$/)
|
84
|
+
if v.match /^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/
|
85
|
+
v = Date.parse v
|
86
|
+
else
|
87
|
+
v = Time.parse v
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
instance_variable_set "@#{f}", v
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
define_method f do
|
97
|
+
value = instance_variable_get "@#{f}"
|
98
|
+
unless @disable_association_resolving
|
99
|
+
#lazily load in value if it hasn't been loaded yet
|
100
|
+
if value.nil?
|
101
|
+
unless @loaded_attributes[f]
|
102
|
+
refresh
|
103
|
+
value = instance_variable_get "@#{f}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
#lazily load association if it hasn't been loaded yet
|
108
|
+
if value.kind_of? Array
|
109
|
+
value = value.map do |v|
|
110
|
+
if association_attribute? v
|
111
|
+
load_association v
|
112
|
+
else
|
113
|
+
v
|
114
|
+
end
|
115
|
+
end
|
116
|
+
send "#{f}=".to_sym, value
|
117
|
+
else
|
118
|
+
value = load_association value if association_attribute? value
|
119
|
+
send "#{f}=".to_sym, value
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
value
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
def client
|
132
|
+
@client
|
133
|
+
end
|
134
|
+
|
135
|
+
def assign_client v
|
136
|
+
@client = v
|
137
|
+
end
|
138
|
+
|
139
|
+
def query_engine
|
140
|
+
@query_engine
|
141
|
+
end
|
142
|
+
|
143
|
+
def assign_query_engine v
|
144
|
+
@query_engine = v
|
145
|
+
end
|
146
|
+
|
147
|
+
def association_attribute? attribute_value
|
148
|
+
if attribute_value.kind_of? Hash
|
149
|
+
return true if attribute_value['url'].present?
|
150
|
+
end
|
151
|
+
false
|
152
|
+
end
|
153
|
+
|
154
|
+
def pluralized_resource_type_from_association_attribute attribute_value
|
155
|
+
attribute_value['url'].split('v1.1/').last.split('/').first
|
156
|
+
end
|
157
|
+
|
158
|
+
def singularized_resource_type_from_association_attribute attribute_value
|
159
|
+
pluralized_resource_type_from_association_attribute(attribute_value).chop
|
160
|
+
end
|
161
|
+
|
162
|
+
def load_association value
|
163
|
+
client.send(pluralized_resource_type_from_association_attribute(value).to_sym).find value['id']
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module Models
|
4
|
+
class Conversation < Base
|
5
|
+
def self.fields
|
6
|
+
%w{id
|
7
|
+
url
|
8
|
+
status
|
9
|
+
is_priority
|
10
|
+
contains_private
|
11
|
+
tags
|
12
|
+
author
|
13
|
+
channels
|
14
|
+
assigned_to
|
15
|
+
content_ids
|
16
|
+
handling_times}.map &:to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
attributize_tags
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module Models
|
4
|
+
class Report < Base
|
5
|
+
def self.fields
|
6
|
+
%w{account name generation_start_date url date_from generated_by id failure generated_date date_to download date_type}
|
7
|
+
end
|
8
|
+
|
9
|
+
attributize_tags
|
10
|
+
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module QueryEngines
|
4
|
+
class Account < Base
|
5
|
+
|
6
|
+
|
7
|
+
def initialize client
|
8
|
+
super client
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def model_klass
|
14
|
+
Conversocial::Resources::Models::Account
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module QueryEngines
|
4
|
+
class Author < Base
|
5
|
+
undef_method :fetch
|
6
|
+
|
7
|
+
def initialize client
|
8
|
+
super client
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def model_klass
|
14
|
+
Conversocial::Resources::Models::Author
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Conversocial
|
4
|
+
module Resources
|
5
|
+
module QueryEngines
|
6
|
+
class Base
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
attr_reader :client, :query_params
|
10
|
+
|
11
|
+
def initialize client
|
12
|
+
@client = client
|
13
|
+
clear
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_fetch_query_params
|
17
|
+
{}
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_find_query_params
|
21
|
+
{}
|
22
|
+
end
|
23
|
+
|
24
|
+
def each &block
|
25
|
+
fetch.each do |member|
|
26
|
+
block.call(member)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def each_page &block
|
31
|
+
@query_params[:fields] ||= model_klass.fields.join(',')
|
32
|
+
response = fetch_ex add_query_params("", default_fetch_query_params.merge(@query_params))
|
33
|
+
begin
|
34
|
+
continue = block.call response[:items]
|
35
|
+
continue = true
|
36
|
+
if continue
|
37
|
+
next_page_url = (response[:json]['paging'] || {})['next_page']
|
38
|
+
if next_page_url.present?
|
39
|
+
response = fetch_ex next_page_url
|
40
|
+
else
|
41
|
+
response = nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end while response && continue
|
45
|
+
end
|
46
|
+
|
47
|
+
def clear
|
48
|
+
@query_params = {}
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def where options
|
53
|
+
@query_params.merge! options
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
57
|
+
def new params={}
|
58
|
+
new_instance = model_klass.new params
|
59
|
+
new_instance.send :assign_client, client
|
60
|
+
new_instance.send :assign_query_engine, self
|
61
|
+
new_instance
|
62
|
+
end
|
63
|
+
|
64
|
+
def find find_id
|
65
|
+
@query_params[:fields] ||= model_klass.fields.join(',')
|
66
|
+
|
67
|
+
json = get_json add_query_params("/#{find_id}", default_find_query_params.merge(@query_params))
|
68
|
+
clear
|
69
|
+
if json
|
70
|
+
new json[resource_name]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def size
|
75
|
+
fetch.size
|
76
|
+
end
|
77
|
+
|
78
|
+
def count
|
79
|
+
size
|
80
|
+
end
|
81
|
+
|
82
|
+
def last
|
83
|
+
fetch.last
|
84
|
+
end
|
85
|
+
|
86
|
+
def fetch
|
87
|
+
@query_params[:fields] ||= model_klass.fields.join(',')
|
88
|
+
(fetch_ex add_query_params("", default_fetch_query_params.merge(@query_params)))[:items]
|
89
|
+
end
|
90
|
+
|
91
|
+
protected
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
def fetch_ex url
|
98
|
+
json = get_json url
|
99
|
+
clear
|
100
|
+
items = []
|
101
|
+
if json
|
102
|
+
items = json[plural_resource_name].map do |instance_params|
|
103
|
+
new instance_params
|
104
|
+
end
|
105
|
+
end
|
106
|
+
{:items => items, :json => json}
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
def resource_name
|
111
|
+
demodulize(model_klass.name).downcase
|
112
|
+
end
|
113
|
+
|
114
|
+
def plural_resource_name
|
115
|
+
resource_name + 's'
|
116
|
+
end
|
117
|
+
|
118
|
+
def base_path
|
119
|
+
"/" + plural_resource_name
|
120
|
+
end
|
121
|
+
|
122
|
+
def absolute_path path
|
123
|
+
if path.match /^http/
|
124
|
+
path
|
125
|
+
else
|
126
|
+
"https://api.conversocial.com/v1.1#{base_path}#{path}"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def get_json path
|
131
|
+
#puts "getting json for #{absolute_path(path)}"
|
132
|
+
|
133
|
+
uri = URI absolute_path(path)
|
134
|
+
response = Net::HTTP.start(uri.host, uri.port,
|
135
|
+
:use_ssl => uri.scheme == 'https',
|
136
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
|
137
|
+
|
138
|
+
request = Net::HTTP::Get.new uri.request_uri
|
139
|
+
request.basic_auth client.key, client.secret
|
140
|
+
|
141
|
+
http.request request # Net::HTTPResponse object
|
142
|
+
end
|
143
|
+
|
144
|
+
json = JSON.parse response.body
|
145
|
+
|
146
|
+
if response.kind_of? Net::HTTPSuccess
|
147
|
+
json
|
148
|
+
else
|
149
|
+
if 404 == response.code.to_i
|
150
|
+
if json['message'] == "No such #{resource_name}"
|
151
|
+
# puts "returning nil here"
|
152
|
+
return nil
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
#some unknown error happened so raise standard exception
|
157
|
+
raise Conversocial::Resources::Exceptions::Base.new response.code, response.message, json['message']
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def add_query_params(url, params_to_add)
|
162
|
+
uri = URI url
|
163
|
+
params = (params_to_add || {}).merge URI.decode_www_form(uri.query.to_s).to_h
|
164
|
+
return url if params.blank?
|
165
|
+
uri.query = URI.encode_www_form(params)
|
166
|
+
uri.to_s
|
167
|
+
end
|
168
|
+
|
169
|
+
def demodulize(path)
|
170
|
+
path = path.to_s
|
171
|
+
if i = path.rindex('::')
|
172
|
+
path[(i+2)..-1]
|
173
|
+
else
|
174
|
+
path
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module QueryEngines
|
4
|
+
class Channel < Base
|
5
|
+
def initialize client
|
6
|
+
super client
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def model_klass
|
12
|
+
Conversocial::Resources::Models::Channel
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module QueryEngines
|
4
|
+
class Conversation < Base
|
5
|
+
include Conversocial::Resources::QueryEngines
|
6
|
+
|
7
|
+
def initialize client
|
8
|
+
super client
|
9
|
+
end
|
10
|
+
|
11
|
+
def default_fetch_query_params
|
12
|
+
{:is_priority => false, :include => 'content'}
|
13
|
+
end
|
14
|
+
|
15
|
+
def limit l
|
16
|
+
where :page_size => l
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def model_klass
|
22
|
+
Conversocial::Resources::Models::Conversation
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module QueryEngines
|
4
|
+
class Keyvalue < Base
|
5
|
+
include Conversocial::Resources::QueryEngines
|
6
|
+
|
7
|
+
def initialize client
|
8
|
+
super client
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def model_klass
|
14
|
+
Conversocial::Resources::Models::Keyvalue
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module QueryEngines
|
4
|
+
class Report < Base
|
5
|
+
include Conversocial::Resources::QueryEngines
|
6
|
+
|
7
|
+
def initialize client
|
8
|
+
super client
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def model_klass
|
14
|
+
Conversocial::Resources::Models::Report
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module QueryEngines
|
4
|
+
class Tag < Base
|
5
|
+
include Conversocial::Resources::QueryEngines
|
6
|
+
|
7
|
+
def initialize client
|
8
|
+
super client
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def model_klass
|
14
|
+
Conversocial::Resources::Models::Tag
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Conversocial
|
2
|
+
module Resources
|
3
|
+
module QueryEngines
|
4
|
+
class User < Base
|
5
|
+
include Conversocial::Resources::QueryEngines
|
6
|
+
|
7
|
+
def initialize client
|
8
|
+
super client
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def model_klass
|
14
|
+
Conversocial::Resources::Models::User
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: conversocial
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Misha Conway
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Ruby gem that wraps the conversocial api in an ORM pattern
|
42
|
+
email:
|
43
|
+
- mishaAconway@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- conversocial.gemspec
|
54
|
+
- lib/conversocial.rb
|
55
|
+
- lib/conversocial/client.rb
|
56
|
+
- lib/conversocial/resources.rb
|
57
|
+
- lib/conversocial/resources/exceptions/base.rb
|
58
|
+
- lib/conversocial/resources/models.rb
|
59
|
+
- lib/conversocial/resources/models/account.rb
|
60
|
+
- lib/conversocial/resources/models/author.rb
|
61
|
+
- lib/conversocial/resources/models/base.rb
|
62
|
+
- lib/conversocial/resources/models/channel.rb
|
63
|
+
- lib/conversocial/resources/models/conversation.rb
|
64
|
+
- lib/conversocial/resources/models/keyvalue.rb
|
65
|
+
- lib/conversocial/resources/models/report.rb
|
66
|
+
- lib/conversocial/resources/models/tag.rb
|
67
|
+
- lib/conversocial/resources/models/user.rb
|
68
|
+
- lib/conversocial/resources/query_engines.rb
|
69
|
+
- lib/conversocial/resources/query_engines/account.rb
|
70
|
+
- lib/conversocial/resources/query_engines/author.rb
|
71
|
+
- lib/conversocial/resources/query_engines/base.rb
|
72
|
+
- lib/conversocial/resources/query_engines/channel.rb
|
73
|
+
- lib/conversocial/resources/query_engines/conversation.rb
|
74
|
+
- lib/conversocial/resources/query_engines/keyvalue.rb
|
75
|
+
- lib/conversocial/resources/query_engines/report.rb
|
76
|
+
- lib/conversocial/resources/query_engines/tag.rb
|
77
|
+
- lib/conversocial/resources/query_engines/user.rb
|
78
|
+
- lib/conversocial/version.rb
|
79
|
+
homepage: ''
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Ruby gem that wraps the conversocial api in an ORM pattern
|
103
|
+
test_files: []
|