littlebird-api-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +34 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +19 -0
- data/LICENSE.txt +22 -0
- data/README.md +244 -0
- data/Rakefile +1 -0
- data/lib/client.rb +22 -0
- data/lib/errors/authorization.rb +4 -0
- data/lib/errors/internal.rb +4 -0
- data/lib/errors/parameter.rb +4 -0
- data/lib/errors/rate_limit.rb +4 -0
- data/lib/little_bird_errors.rb +11 -0
- data/lib/request.rb +134 -0
- data/lib/response.rb +46 -0
- data/lib/response_type.rb +40 -0
- data/lib/response_types/api_structure.rb +2 -0
- data/lib/response_types/community.rb +2 -0
- data/lib/response_types/compare_result.rb +9 -0
- data/lib/response_types/discover_url.rb +2 -0
- data/lib/response_types/gexf.rb +7 -0
- data/lib/response_types/graph.rb +67 -0
- data/lib/response_types/graph_attribute.rb +2 -0
- data/lib/response_types/screen_name_resolution.rb +2 -0
- data/lib/response_types/topic.rb +2 -0
- data/lib/response_types/tweet.rb +2 -0
- data/lib/response_types/user.rb +5 -0
- data/lib/response_types/user_metric.rb +2 -0
- data/little-bird-api-client.gemspec +30 -0
- data/little_bird.rb +0 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDMyZGY5ZDQ4ZWRjZjIxZGU4NDU5YTYwYTkxNDFhZjQ1NzViMWY2Ng==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWQ4NWEwYmQzNzI1MzFlMzk5NzgyODk2ZjQ1MjY5ZGJiM2UzMDQ1Mw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NjM1MjNhZDk0YjEwMWFjNGQ0MDBjOGM1MGY3NjQ1YWRkZTU3YzUxNmFjNmE1
|
10
|
+
MDA3ZTJmMGNkMzdmZDQzY2RlYjkzOGU3Nzc3NjRhNzEwYmIxODVlNzZhN2Nk
|
11
|
+
YjA0YWM0MmExZTU2MzkzZTJhZWI2Mjc2NTFlZTVlMzJkYjkxYzM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTgyZTU3ODg2MDRhZjI0NWE3YTBhMjNjNGI2ZjJjYmMzMTcxNzcyNWM4Njc4
|
14
|
+
Y2Y2ZThkOWRiNWJiZGE3ZjU0YTNjNjk2YmQ3NWI1ZTRkNDMyNjRhYTdhZjEy
|
15
|
+
NGMyMTgzOWFmZjkxZjYxMWU2YjYwOGMwMzBmMWFlOTU2YzZlZDk=
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
GEM
|
2
|
+
specs:
|
3
|
+
coderay (1.1.0)
|
4
|
+
method_source (0.8.2)
|
5
|
+
netrc (0.7.7)
|
6
|
+
pry (0.9.12.6)
|
7
|
+
coderay (~> 1.0)
|
8
|
+
method_source (~> 0.8)
|
9
|
+
slop (~> 3.4)
|
10
|
+
rest_client (1.7.3)
|
11
|
+
netrc (~> 0.7.7)
|
12
|
+
slop (3.5.0)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
pry
|
19
|
+
rest_client
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Devin Gaffney
|
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,244 @@
|
|
1
|
+
api-client
|
2
|
+
==========
|
3
|
+
API Client for use with LB API
|
4
|
+
|
5
|
+
|
6
|
+
Usage
|
7
|
+
---------------------
|
8
|
+
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
>> client = LittleBird::Client.new(api_key)
|
12
|
+
# To specify version and host, add those options after api key (eg LittleBird::Client.new(api_key, 1, "localhost"))
|
13
|
+
>> client.content_top(term: "SNA")
|
14
|
+
=> [#<Tweet:0x007f809d1a31a8 @id=471361237381439488, @id_str="471361237381439488", @favorite_count=12, @retweet_count=27, @screen_name="TechCrunch", @user_id=816653, @user_id_str="816653", @urls=["http://bit.ly/SLQYr9"], @created_at=2014-05-27 11:44:11 -0700, @client=#<LittleBird::Client:0x007f809e16ccb0 @api_key="533c98700765e035b129bcf2", @version=:v1, @base_url="api.getlittlebird.com">>]
|
15
|
+
```
|
16
|
+
## Endpoints
|
17
|
+
|
18
|
+
### compare_twitter_screen_name
|
19
|
+
Compare a user to a given search term - show the set of relationships the user has in relation to people related to a term
|
20
|
+
|
21
|
+
Parameter possibilities:
|
22
|
+
[:screen_name, :term]
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
>> client.compare_twitter_screen_name(term: "SNA", screen_name: "zephoria")
|
26
|
+
```
|
27
|
+
|
28
|
+
### content_top
|
29
|
+
Return metadata around high-performing twitter statuses from insiders given a topic
|
30
|
+
|
31
|
+
Parameter possibilities:
|
32
|
+
[:term]
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
>> client.content_top(term: "SNA")
|
36
|
+
```
|
37
|
+
|
38
|
+
### content_recent
|
39
|
+
Return metadata around the most recent twitter statuses from insiders given a topic
|
40
|
+
|
41
|
+
Parameter possibilities:
|
42
|
+
[:term]
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
>> client.content_recent(term: "SNA")
|
46
|
+
```
|
47
|
+
|
48
|
+
### graph_add
|
49
|
+
Add users to an existing graph created by the API account
|
50
|
+
|
51
|
+
Parameter possibilities:
|
52
|
+
[:domain, :id, :identity],
|
53
|
+
[:domain, :id, :identities]
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
>> client.graph_add(identities: [19512246, 18911399, 2192301, 16453892, 1002913782], domain: "twitter", id: "533c98700765e035b129bcf2")
|
57
|
+
```
|
58
|
+
|
59
|
+
### graph_analyze
|
60
|
+
Trigger an analysis of an existing non-empty graph created by the API account.
|
61
|
+
|
62
|
+
Parameter possibilities:
|
63
|
+
[:id]
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
>> client.graph_analyze(id: "533c98700765e035b129bcf2")
|
67
|
+
```
|
68
|
+
|
69
|
+
### graph_clear_attribute
|
70
|
+
Clear previously set attributes for a set of nodes contained in an existing non empty graph.
|
71
|
+
|
72
|
+
Parameter possibilities:
|
73
|
+
[:domain, :id, :identities, :name],
|
74
|
+
[:domain, :id, :identity, :name],
|
75
|
+
[:id, :name, :node_ids],
|
76
|
+
[:id, :name, :node_id]
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
>> client.graph_clear_attribute(identities: [19512246, 18911399, 2192301, 16453892, 1002913782], domain: "twitter", id: "533c98700765e035b129bcf2", name: "test")
|
80
|
+
```
|
81
|
+
|
82
|
+
### graph_community
|
83
|
+
Returns an overview of the distinct communities detected in a given graph via their modularity class. Set the 'users' variable to ```true``` to show the actual users per community rather than an overview of the groups.
|
84
|
+
|
85
|
+
Parameter possibilities:
|
86
|
+
[:analysis_id],
|
87
|
+
[:analysis_id, :users]
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
>> client.graph_community(analysis_id: "533c98700765e035b129bcf2")
|
91
|
+
```
|
92
|
+
|
93
|
+
### graph_create
|
94
|
+
Create a new graph.
|
95
|
+
|
96
|
+
Parameter possibilities:
|
97
|
+
[:term]
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
>> client.graph_create(term: "SNA")
|
101
|
+
```
|
102
|
+
|
103
|
+
### graph_download
|
104
|
+
Returns an export of the graph as specified by the format variable - can currently be set to "gexf", "csv", or "sigmajs".
|
105
|
+
|
106
|
+
Parameter possibilities:
|
107
|
+
[:format, :analysis_id]
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
>> client.graph_download(analysis_id: "533c98700765e035b129bcf2", format: "gexf")
|
111
|
+
```
|
112
|
+
|
113
|
+
### graph_drop
|
114
|
+
Delete either an analysis or a graph entirely from the account.
|
115
|
+
|
116
|
+
Parameter possibilities:
|
117
|
+
[:id],
|
118
|
+
[:analysis_id]
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
>> client.graph_drop(analysis_id: "533c98700765e035b129bcf2")
|
122
|
+
```
|
123
|
+
|
124
|
+
### graph_info
|
125
|
+
Display information about a given graph
|
126
|
+
|
127
|
+
Parameter possibilities:
|
128
|
+
[:id]
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
>> client.graph_info(id: "533c98700765e035b129bcf2")
|
132
|
+
```
|
133
|
+
|
134
|
+
### graph_metric
|
135
|
+
Display a set of values per node in a given graph and a metric of interest. Current metrics provided are "closeness", "betweenness", "coreness"", "modularity", and "degree"
|
136
|
+
|
137
|
+
Parameter possibilities:
|
138
|
+
[:analysis_id, :metric],
|
139
|
+
[:analysis_id, :metric, :users]
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
>> client.graph_metric(analysis_id: "533c98700765e035b129bcf2", metric: "betweenness")
|
143
|
+
```
|
144
|
+
|
145
|
+
### graph_list
|
146
|
+
List all graphs that this API account has created.
|
147
|
+
|
148
|
+
Parameter possibilities:
|
149
|
+
None
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
>> client.graph_list
|
153
|
+
```
|
154
|
+
|
155
|
+
### graph_set_attribute
|
156
|
+
Set a series of attributes for a set of nodes (and their values in a separate array, mapped to the position of the node IDs) on a given graph with a given name for the attribute. Nodes must already exist on the graph, otherwise the setting of the attribute will fail.
|
157
|
+
|
158
|
+
Parameter possibilities:
|
159
|
+
[:domain, :id, :identities, :name, :values],
|
160
|
+
[:domain, :id, :identity, :name, :value],
|
161
|
+
[:id, :name, :node_ids, :values],
|
162
|
+
[:id, :name, :node_id, :value]
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
>> client.graph_set_attribute(identities: [19512246, 18911399, 2192301, 16453892, 1002913782], domain: "twitter", id: "533c98700765e035b129bcf2", name: "test", values: [1,2,3,4,5])
|
166
|
+
```
|
167
|
+
|
168
|
+
### graph_set_recursive_attribute
|
169
|
+
Set a series of attributes for a set of nodes (and their values in a separate array, mapped to the position of the node IDs) on a given graph with a given name for the attribute. Nodes must already exist on the graph, otherwise the setting of the attribute will fail. Unlike normal attributes, recursive attributes will generate a score for all other users where a score was not assigned which is an indicator to the distance to nodes that have the variable set.
|
170
|
+
|
171
|
+
Parameter possibilities:
|
172
|
+
[:domain, :id, :identities, :name, :values],
|
173
|
+
[:domain, :id, :identity, :name, :value],
|
174
|
+
[:id, :name, :node_ids, :values],
|
175
|
+
[:id, :name, :node_id, :value]
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
>> client.graph_set_recursive_attribute(identities: [19512246, 18911399, 2192301, 16453892, 1002913782], domain: "twitter", id: "533c98700765e035b129bcf2", name: "test", values: [1,1,1,1,1])
|
179
|
+
```
|
180
|
+
|
181
|
+
### identity_lookup
|
182
|
+
Return an influencer and their primary account data given either a domain/identity pair or a direct node_id
|
183
|
+
|
184
|
+
Parameter possibilities:
|
185
|
+
[:node_id_],
|
186
|
+
[:domain, :identity]
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
>> client.identity_lookup(identity: 19512246, domain: "twitter")
|
190
|
+
```
|
191
|
+
|
192
|
+
### influencer_discover
|
193
|
+
Return a set of influencers given a topic, along with some data about those users. Set Domain to "facebook", "twitter", "youtube", etc to only return users with accounts on those services.
|
194
|
+
|
195
|
+
Parameter possibilities:
|
196
|
+
[:term],
|
197
|
+
[:domain, :term]
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
>> client.influencer_discover(identities: [19512246, 18911399, 2192301, 16453892, 1002913782], domain: "twitter", id: "533c98700765e035b129bcf2", name: "test", values: [1,1,1,1,1])
|
201
|
+
```
|
202
|
+
|
203
|
+
### influencer_lookup
|
204
|
+
Return a set of interests shared by influencers, along with a score. Set Domain to "facebook", "twitter", "youtube", etc to only return users with accounts on those services.
|
205
|
+
|
206
|
+
Parameter possibilities:
|
207
|
+
[:domain, :identities],
|
208
|
+
[:domain, :identity]
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
>> client.influencer_lookup(identities: [19512246, 18911399, 2192301, 16453892, 1002913782], domain: "twitter", id: "533c98700765e035b129bcf2", name: "test", values: [1,1,1,1,1])
|
212
|
+
```
|
213
|
+
|
214
|
+
### misc_screen_name_lookup
|
215
|
+
Lookup ids from twitter given the screen names of a set of users.
|
216
|
+
|
217
|
+
Parameter possibilities:
|
218
|
+
[:domain, :screen_names],
|
219
|
+
[:domain, :screen_name]
|
220
|
+
|
221
|
+
```ruby
|
222
|
+
>> client.misc_screen_name_lookup(screen_names: ["dgaff"], domain: "twitter")
|
223
|
+
```
|
224
|
+
|
225
|
+
### info_topology
|
226
|
+
Return information about available endpoints on the API - set include_rate_limit_status to true to see current rate limits per endpoint.
|
227
|
+
|
228
|
+
Parameter possibilities:
|
229
|
+
[:include_rate_limit_status]
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
>> client.info_topology
|
233
|
+
```
|
234
|
+
|
235
|
+
### topic_search
|
236
|
+
Return links to API endpoints for existing reports given a term to search on.
|
237
|
+
|
238
|
+
Parameter possibilities:
|
239
|
+
[:term]
|
240
|
+
|
241
|
+
```ruby
|
242
|
+
>> client.topic_search(term: "SNA")
|
243
|
+
```
|
244
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/client.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module LittleBird
|
2
|
+
module Request;end
|
3
|
+
module Response;end
|
4
|
+
class Client
|
5
|
+
VERSION = "0.0.1"
|
6
|
+
include Request
|
7
|
+
include Response
|
8
|
+
def initialize(api_key, version=1, base_url="api.getlittlebird.com")
|
9
|
+
@api_key = api_key
|
10
|
+
@version = :"v#{version}"
|
11
|
+
@base_url = base_url
|
12
|
+
end
|
13
|
+
|
14
|
+
def graphs
|
15
|
+
self.graph_list
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_graph(term)
|
19
|
+
self.graph_create(term)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/request.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
module LittleBird
|
2
|
+
module Request
|
3
|
+
def base_url
|
4
|
+
"http://#{@base_url}/#{@version}/"
|
5
|
+
end
|
6
|
+
|
7
|
+
def endpoints
|
8
|
+
{
|
9
|
+
v1:
|
10
|
+
{
|
11
|
+
compare_twitter_screen_name: "compare/twitter_screen_name",
|
12
|
+
content_top: "content/top",
|
13
|
+
content_recent: "content/recent",
|
14
|
+
graph_add: "graph/add",
|
15
|
+
graph_analyze: "graph/analyze",
|
16
|
+
graph_clear_attribute: "graph/clear_attribute",
|
17
|
+
graph_community: "graph/community",
|
18
|
+
graph_create: "graph/create",
|
19
|
+
graph_download: "graph/download",
|
20
|
+
graph_drop: "graph/drop",
|
21
|
+
graph_info: "graph/info",
|
22
|
+
graph_metric: "graph/metric",
|
23
|
+
graph_list: "graph/list",
|
24
|
+
graph_set_attribute: "graph/set_attribute",
|
25
|
+
graph_set_recursive_attribute: "graph/set_recursive_attribute",
|
26
|
+
identity_lookup: "identity/lookup",
|
27
|
+
influencer_discover: "influencer/discover",
|
28
|
+
influencer_lookup: "influencer/lookup",
|
29
|
+
misc_screen_name_lookup: "misc/screen_name_lookup",
|
30
|
+
info_topology: "info/topology",
|
31
|
+
topic_search: "topic/search"
|
32
|
+
}
|
33
|
+
}[@version]
|
34
|
+
end
|
35
|
+
|
36
|
+
def endpoint_http_methods
|
37
|
+
{
|
38
|
+
v1:
|
39
|
+
{
|
40
|
+
compare_twitter_screen_name: :get,
|
41
|
+
content_top: :get,
|
42
|
+
content_recent: :get,
|
43
|
+
graph_add: :post,
|
44
|
+
graph_analyze: :get,
|
45
|
+
graph_clear_attribute: :post,
|
46
|
+
graph_community: :get,
|
47
|
+
graph_create: :post,
|
48
|
+
graph_download: :get,
|
49
|
+
graph_drop: :post,
|
50
|
+
graph_info: :get,
|
51
|
+
graph_metric: :post,
|
52
|
+
graph_list: :post,
|
53
|
+
graph_set_attribute: :post,
|
54
|
+
graph_set_recursive_attribute: :post,
|
55
|
+
identity_lookup: :get,
|
56
|
+
influencer_discover: :get,
|
57
|
+
influencer_lookup: :get,
|
58
|
+
misc_screen_name_lookup: :post,
|
59
|
+
info_topology: :get,
|
60
|
+
topic_search: :get
|
61
|
+
}
|
62
|
+
}[@version]
|
63
|
+
end
|
64
|
+
|
65
|
+
def response_types_by_endpoint
|
66
|
+
{
|
67
|
+
v1:
|
68
|
+
{
|
69
|
+
compare_twitter_screen_name: CompareResult,
|
70
|
+
content_top: [Tweet],
|
71
|
+
content_recent: [Tweet],
|
72
|
+
graph_add: Graph,
|
73
|
+
graph_analyze: Graph,
|
74
|
+
graph_clear_attribute: GraphAttribute,
|
75
|
+
graph_community: [Community],
|
76
|
+
graph_create: Graph,
|
77
|
+
graph_download: GEXF,
|
78
|
+
graph_drop: Graph,
|
79
|
+
graph_info: Graph,
|
80
|
+
graph_metric: [UserMetric],
|
81
|
+
graph_list: [Graph],
|
82
|
+
graph_set_attribute: GraphAttribute,
|
83
|
+
graph_set_recursive_attribute: GraphAttribute,
|
84
|
+
identity_lookup: User,
|
85
|
+
influencer_discover: [User],
|
86
|
+
influencer_lookup: [Topic],
|
87
|
+
misc_screen_name_lookup: [ScreenNameResolution],
|
88
|
+
info_topology: APIStructure,
|
89
|
+
topic_search: [DiscoverURL]
|
90
|
+
}
|
91
|
+
}[@version]
|
92
|
+
end
|
93
|
+
|
94
|
+
def extension
|
95
|
+
".json"
|
96
|
+
end
|
97
|
+
|
98
|
+
def method_missing(method, *args)
|
99
|
+
if endpoints.include?(method)
|
100
|
+
interpret(
|
101
|
+
request(
|
102
|
+
method, args[0]||{}
|
103
|
+
), response_types_by_endpoint[method]
|
104
|
+
)
|
105
|
+
else
|
106
|
+
super
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def url_for(endpoint)
|
111
|
+
base_url+endpoints[endpoint]+extension
|
112
|
+
end
|
113
|
+
|
114
|
+
def parse(response)
|
115
|
+
JSON.parse(response)
|
116
|
+
end
|
117
|
+
|
118
|
+
def request(endpoint, args)
|
119
|
+
puts args.inspect
|
120
|
+
begin
|
121
|
+
parse(
|
122
|
+
RestClient::Request.execute(
|
123
|
+
method: endpoint_http_methods[endpoint],
|
124
|
+
url: url_for(endpoint),
|
125
|
+
payload: args.merge(api_key: @api_key),
|
126
|
+
timeout: 60000
|
127
|
+
)
|
128
|
+
)
|
129
|
+
rescue => e
|
130
|
+
parse(e.response)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/lib/response.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module LittleBird
|
2
|
+
module Response
|
3
|
+
def error(response)
|
4
|
+
{
|
5
|
+
authorization: AuthorizationError.new(response),
|
6
|
+
internal: InternalError.new(response),
|
7
|
+
parameter: ParameterError.new(response),
|
8
|
+
rate_limit: RateLimitError.new(response)
|
9
|
+
}[response["error_type"].to_sym]
|
10
|
+
end
|
11
|
+
|
12
|
+
def response_is_an_error(response)
|
13
|
+
response.class == Hash && !response["error"].nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def interpret(response, cast_class)
|
17
|
+
raise error(response), response["error"] if response_is_an_error(response)
|
18
|
+
if cast_class.class == Array
|
19
|
+
return iterate(response, cast_class.first)
|
20
|
+
else
|
21
|
+
return respond_as_class(response, cast_class)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def iterate(response, cast_class)
|
26
|
+
response.map do |response_obj|
|
27
|
+
respond_as_class(response_obj, cast_class)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_client(object)
|
32
|
+
object.instance_eval { class << self; self end }.send(:attr_accessor, :client)
|
33
|
+
object.client = self
|
34
|
+
end
|
35
|
+
|
36
|
+
def respond_as_class(response_obj, cast_class)
|
37
|
+
object = cast_class.new(response_obj)
|
38
|
+
set_client(object)
|
39
|
+
object
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# load 'little_bird.rb'
|
45
|
+
# client = LittleBird::Client.new("533c98700765e035b1000001", 1, "0.0.0.0:8083")
|
46
|
+
# graph = client.graph_list.first
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class ResponseType
|
2
|
+
def initialize(attrs)
|
3
|
+
attrs.each do |key, value|
|
4
|
+
self.instance_eval { class << self; self end }.send(:attr_accessor, key.to_sym)
|
5
|
+
self.send(key+"=", parse_value(key, value))
|
6
|
+
end
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def parse_value(key, value)
|
11
|
+
set_as_time_if_timestamp(key, value)
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_as_time_if_timestamp(key, value)
|
15
|
+
self.class.timestamped_keys.include?(key) && !value.nil? ? Time.parse(value) : value
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.timestamped_keys
|
19
|
+
["created_at", "started_at", "updated_at", "finished_at"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_json(*a)
|
23
|
+
{
|
24
|
+
'json_class' => self.class.name,
|
25
|
+
'data' => attributes
|
26
|
+
}.to_json(*a)
|
27
|
+
end
|
28
|
+
|
29
|
+
def attributes
|
30
|
+
Hash[useful_attribute_names.zip(useful_attribute_names.map{|attribute| self.send(attribute)})]
|
31
|
+
end
|
32
|
+
|
33
|
+
def attribute_names
|
34
|
+
instance_variables.collect{|ivar| ivar.to_s.gsub("@", "")}
|
35
|
+
end
|
36
|
+
|
37
|
+
def useful_attribute_names
|
38
|
+
attribute_names-["client"]
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class Graph < ResponseType
|
2
|
+
def add(ids, opts={})
|
3
|
+
client.graph_add({identities: [ids].flatten, id: id}.merge(opts))
|
4
|
+
end
|
5
|
+
|
6
|
+
def download_gexf_to(analysis_id, file=StringIO.new)
|
7
|
+
client.graph_download(analysis_id: analysis_id, format: "gexf").to_file(file)
|
8
|
+
end
|
9
|
+
|
10
|
+
def download_csv_to(analysis_id, file=StringIO.new)
|
11
|
+
client.graph_download(analysis_id: analysis_id, format: "csv").to_file(file)
|
12
|
+
end
|
13
|
+
|
14
|
+
def analyze
|
15
|
+
client.graph_analyze(id: id)
|
16
|
+
end
|
17
|
+
|
18
|
+
def clear_attributes(opts)
|
19
|
+
names = opts.delete(:names) || opts.delete("names")
|
20
|
+
names.each do |name|
|
21
|
+
client.graph_clear_attribute(opts.merge(id: id, name: name))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def clear_attribute(opts)
|
26
|
+
client.graph_analyze(opts.merge(id: id))
|
27
|
+
end
|
28
|
+
|
29
|
+
def communities(analysis_id)
|
30
|
+
client.graph_community(analysis_id: analysis_id)
|
31
|
+
end
|
32
|
+
|
33
|
+
def community(analysis_id, community_id)
|
34
|
+
client.graph_community(analysis_id: analysis_id, community_id: community_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def communities_users(analysis_id)
|
38
|
+
client.graph_community(analysis_id: analysis_id, users: true)
|
39
|
+
end
|
40
|
+
|
41
|
+
def community_users(analysis_id, community_id)
|
42
|
+
client.graph_community(analysis_id: analysis_id, community_id: community_id, users: true)
|
43
|
+
end
|
44
|
+
|
45
|
+
def drop
|
46
|
+
client.graph_drop(id: id)
|
47
|
+
end
|
48
|
+
|
49
|
+
def info
|
50
|
+
client.graph_info(id: id)
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_attribute
|
54
|
+
client.graph_set_attribute(opts.merge(id: id))
|
55
|
+
end
|
56
|
+
|
57
|
+
#usage params = {api_key: "533c98700765e035b1000001", term: "SNA", nodes: [19512246, 18911399, 2192301], attributes: {"name" => {"19512246" => 1, "18911399" => 2}}`, domain: "twitter"}
|
58
|
+
def self.run(opts={})
|
59
|
+
opts[:api_version] ||= 1
|
60
|
+
opts[:host] ||= "0.0.0.0:8083"
|
61
|
+
client = LittleBird::Client.new(opts[:api_key], opts[:api_version], opts[:host])
|
62
|
+
sub_graph = client.graph_create(term: opts[:term])
|
63
|
+
sub_graph.add(opts[:nodes], domain: opts[:domain])
|
64
|
+
sub_graph.analyze
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
puts lib
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'rest_client'
|
6
|
+
require 'json'
|
7
|
+
require 'time'
|
8
|
+
require 'pry'
|
9
|
+
# binding.pry
|
10
|
+
Dir[File.dirname(__FILE__)+ "/lib/*.rb"].each {|file| require file }
|
11
|
+
Dir[File.dirname(__FILE__)+ "/lib/**/*.rb"].each {|file| require file }
|
12
|
+
print "."
|
13
|
+
Gem::Specification.new do |spec|
|
14
|
+
spec.name = "littlebird-api-client"
|
15
|
+
spec.version = LittleBird::Client::VERSION
|
16
|
+
spec.authors = ["Devin Gaffney"]
|
17
|
+
spec.email = ["devin@getlittlebird.com"]
|
18
|
+
spec.summary = %q{A thin wrapper for the Little Bird api (http://api.getlittlebird.com/index.html)}
|
19
|
+
spec.description = %q{For use with Little Bird! Ya goof!}
|
20
|
+
spec.homepage = ""
|
21
|
+
spec.license = "Proprietary"
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0")
|
24
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
end
|
data/little_bird.rb
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: littlebird-api-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Devin Gaffney
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-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.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
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: For use with Little Bird! Ya goof!
|
42
|
+
email:
|
43
|
+
- devin@getlittlebird.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/client.rb
|
55
|
+
- lib/errors/authorization.rb
|
56
|
+
- lib/errors/internal.rb
|
57
|
+
- lib/errors/parameter.rb
|
58
|
+
- lib/errors/rate_limit.rb
|
59
|
+
- lib/little_bird_errors.rb
|
60
|
+
- lib/request.rb
|
61
|
+
- lib/response.rb
|
62
|
+
- lib/response_type.rb
|
63
|
+
- lib/response_types/api_structure.rb
|
64
|
+
- lib/response_types/community.rb
|
65
|
+
- lib/response_types/compare_result.rb
|
66
|
+
- lib/response_types/discover_url.rb
|
67
|
+
- lib/response_types/gexf.rb
|
68
|
+
- lib/response_types/graph.rb
|
69
|
+
- lib/response_types/graph_attribute.rb
|
70
|
+
- lib/response_types/screen_name_resolution.rb
|
71
|
+
- lib/response_types/topic.rb
|
72
|
+
- lib/response_types/tweet.rb
|
73
|
+
- lib/response_types/user.rb
|
74
|
+
- lib/response_types/user_metric.rb
|
75
|
+
- little-bird-api-client.gemspec
|
76
|
+
- little_bird.rb
|
77
|
+
homepage: ''
|
78
|
+
licenses:
|
79
|
+
- Proprietary
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.2.2
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: A thin wrapper for the Little Bird api (http://api.getlittlebird.com/index.html)
|
101
|
+
test_files: []
|