da_face 0.0.1
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 +20 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +22 -0
- data/README.md +114 -0
- data/Rakefile +2 -0
- data/da_face.gemspec +27 -0
- data/lib/da_face/api/adapter.rb +42 -0
- data/lib/da_face/api/adapters/base.rb +59 -0
- data/lib/da_face/api/adapters/em_http_request_adapter.rb +8 -0
- data/lib/da_face/api/adapters/excon_adapter.rb +33 -0
- data/lib/da_face/api/core.rb +0 -0
- data/lib/da_face/api/push.rb +77 -0
- data/lib/da_face/api/push_log.rb +11 -0
- data/lib/da_face/api/push_log_entry.rb +15 -0
- data/lib/da_face/api/push_subscription.rb +141 -0
- data/lib/da_face/configuration.rb +11 -0
- data/lib/da_face/datasift/da_object.rb +35 -0
- data/lib/da_face/datasift/demographic.rb +12 -0
- data/lib/da_face/datasift/errors.rb +9 -0
- data/lib/da_face/datasift/interaction.rb +33 -0
- data/lib/da_face/datasift/language.rb +14 -0
- data/lib/da_face/datasift/link.rb +34 -0
- data/lib/da_face/datasift/links.rb +38 -0
- data/lib/da_face/datasift/parser.rb +35 -0
- data/lib/da_face/datasift/salience.rb +16 -0
- data/lib/da_face/datasift/twitter.rb +46 -0
- data/lib/da_face/datasift/twitter_delete_notification.rb +16 -0
- data/lib/da_face/datasift/twitter_user_status.rb +37 -0
- data/lib/da_face/errors.rb +7 -0
- data/lib/da_face/twitter/parser.rb +16 -0
- data/lib/da_face/twitter/tweet.rb +49 -0
- data/lib/da_face/twitter/user.rb +55 -0
- data/lib/da_face/utilities.rb +41 -0
- data/lib/da_face/version.rb +3 -0
- data/lib/da_face.rb +69 -0
- data/spec/da_face/api/adapter_spec.rb +58 -0
- data/spec/da_face/api/adapters/base_spec.rb +125 -0
- data/spec/da_face/api/push_log_spec.rb +34 -0
- data/spec/da_face/api/push_spec.rb +108 -0
- data/spec/da_face/api/push_subscription_spec.rb +220 -0
- data/spec/da_face/configuration_spec.rb +15 -0
- data/spec/da_face/datasift/da_object_spec.rb +191 -0
- data/spec/da_face/datasift/demographic_spec.rb +30 -0
- data/spec/da_face/datasift/interaction_spec.rb +93 -0
- data/spec/da_face/datasift/language_spec.rb +45 -0
- data/spec/da_face/datasift/link_spec.rb +80 -0
- data/spec/da_face/datasift/links_spec.rb +70 -0
- data/spec/da_face/datasift/parser_spec.rb +5 -0
- data/spec/da_face/datasift/salience_spec.rb +33 -0
- data/spec/da_face/datasift/twitter_delete_notification_spec.rb +45 -0
- data/spec/da_face/datasift/twitter_spec.rb +56 -0
- data/spec/da_face/datasift/twitter_user_status_spec.rb +36 -0
- data/spec/da_face/twitter/parser_spec.rb +16 -0
- data/spec/da_face/twitter/tweet_spec.rb +77 -0
- data/spec/da_face/twitter/user_spec.rb +116 -0
- data/spec/da_face/utilities_spec.rb +74 -0
- data/spec/da_face_spec.rb +120 -0
- data/spec/fixtures/api_responses/get_subscriptions.json +26 -0
- data/spec/fixtures/api_responses/log.json +126 -0
- data/spec/fixtures/api_responses/validate_success.json +4 -0
- data/spec/fixtures/demographic/simple.json +5 -0
- data/spec/fixtures/interaction/simple.json +28 -0
- data/spec/fixtures/interactions/collection.json +1 -0
- data/spec/fixtures/interactions/simple.json +102 -0
- data/spec/fixtures/language/simple.json +5 -0
- data/spec/fixtures/links/multiples.json +69 -0
- data/spec/fixtures/links/simple.json +65 -0
- data/spec/fixtures/links/simple_failing.json +65 -0
- data/spec/fixtures/notifications/delete.json +10 -0
- data/spec/fixtures/notifications/user_delete.json +16 -0
- data/spec/fixtures/notifications/user_protect.json +16 -0
- data/spec/fixtures/notifications/user_suspend.json +16 -0
- data/spec/fixtures/notifications/user_undelete.json +16 -0
- data/spec/fixtures/notifications/user_unprotect.json +16 -0
- data/spec/fixtures/notifications/user_unsuspend.json +16 -0
- data/spec/fixtures/salience/simple.json +5 -0
- data/spec/fixtures/twitter/retweet.json +70 -0
- data/spec/fixtures/twitter/simple.json +33 -0
- data/spec/integration/stress_spec.rb +16 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/test_spec.rb +7 -0
- metadata +259 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module DaFace
|
|
2
|
+
module Datasift
|
|
3
|
+
class DaObject
|
|
4
|
+
TWITTER_INTERACTION = :twitter_interaction
|
|
5
|
+
TWITTER_DELETE_NOTIFICATION = :delete_notification
|
|
6
|
+
TWITTER_USER_NOTIFICATION = :user_notification
|
|
7
|
+
|
|
8
|
+
attr_reader :interaction, :demographic, :links, :twitter, :salience, :language, :kind
|
|
9
|
+
|
|
10
|
+
def initialize data={}
|
|
11
|
+
if data[:deleted]
|
|
12
|
+
@twitter = DaFace::Datasift::TwitterDeleteNotification.new(data)
|
|
13
|
+
else
|
|
14
|
+
@twitter = DaFace::Datasift::Twitter.new(data[:twitter]) if data[:twitter]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
@interaction = DaFace::Datasift::Interaction.new(data[:interaction]) if data[:interaction]
|
|
18
|
+
@demographic = DaFace::Datasift::Demographic.new(data[:demographic]) if data[:demographic]
|
|
19
|
+
@links = DaFace::Datasift::Links.new(data[:links]) if data[:links]
|
|
20
|
+
@salience = DaFace::Datasift::Salience.new(data[:salience]) if data[:salience]
|
|
21
|
+
@language = DaFace::Datasift::Language.new(data[:language]) if data[:language]
|
|
22
|
+
|
|
23
|
+
set_kind! if data.any?
|
|
24
|
+
|
|
25
|
+
return self
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def set_kind!
|
|
29
|
+
@kind = TWITTER_INTERACTION if @interaction.type == 'twitter'
|
|
30
|
+
@kind = TWITTER_DELETE_NOTIFICATION if @twitter.class == DaFace::Datasift::TwitterDeleteNotification
|
|
31
|
+
@kind = TWITTER_USER_NOTIFICATION if @twitter.class == DaFace::Datasift::TwitterUserStatus
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module DaFace
|
|
2
|
+
module Datasift
|
|
3
|
+
class Interaction
|
|
4
|
+
include DaFace::Utilities
|
|
5
|
+
|
|
6
|
+
attr_reader :author, :content, :created_at, :id, :link,
|
|
7
|
+
:received_at, :schema, :source, :type, :tags,
|
|
8
|
+
:tag_tree
|
|
9
|
+
|
|
10
|
+
def initialize data={}
|
|
11
|
+
allowed_attributes.each do |attr|
|
|
12
|
+
unless data[attr].nil?
|
|
13
|
+
self.instance_variable_set("@#{attr}".to_sym, data[attr])
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
normalize_attributes!
|
|
17
|
+
return self
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def allowed_attributes
|
|
21
|
+
[:author, :content, :created_at, :id, :link,
|
|
22
|
+
:received_at, :schema, :source, :type, :tags,
|
|
23
|
+
:tag_tree]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def normalize_attributes!
|
|
27
|
+
@created_at = parse_timestamp(@created_at) if @created_at
|
|
28
|
+
@received_at = parse_timestamp(@received_at) if @received_at
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module DaFace
|
|
2
|
+
module Datasift
|
|
3
|
+
class Link
|
|
4
|
+
include DaFace::Utilities
|
|
5
|
+
|
|
6
|
+
attr_reader :code, :created_at, :hops, :meta, :normalized_url,
|
|
7
|
+
:retweet_count, :title, :url
|
|
8
|
+
|
|
9
|
+
def initialize data={}
|
|
10
|
+
allowed_attributes.each do |attr|
|
|
11
|
+
if data[attr]
|
|
12
|
+
self.instance_variable_set("@#{attr}".to_sym, data[attr])
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
normalize_attributes!
|
|
16
|
+
|
|
17
|
+
return self
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def allowed_attributes
|
|
21
|
+
[:code, :created_at, :hops, :meta, :normalized_url,
|
|
22
|
+
:retweet_count, :title, :url]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
def normalize_attributes!
|
|
27
|
+
@created_at = parse_timestamp(@created_at) if @created_at
|
|
28
|
+
@hops = @hops.collect{|d| parse_uri(d)} if @hops
|
|
29
|
+
@normalized_url = parse_uri(@normalized_url) if @normalized_url
|
|
30
|
+
@url = parse_uri(@url) if @url
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module DaFace
|
|
2
|
+
module Datasift
|
|
3
|
+
class Links < Array
|
|
4
|
+
def initialize data={}
|
|
5
|
+
self.class.get_elements(data).each do |e|
|
|
6
|
+
self << DaFace::Datasift::Link.new(e)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.get_elements data={}
|
|
11
|
+
hashed_links = []
|
|
12
|
+
unless data.empty?
|
|
13
|
+
data.values.first.size.times do |index|
|
|
14
|
+
hashed_links << get_values(index - 1, data.keys, data)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
return hashed_links
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Recursively search the hash for elements of index 'index'
|
|
21
|
+
# from the arrays inside the hashes.
|
|
22
|
+
def self.get_values index, keys, hash
|
|
23
|
+
new_hash = {}
|
|
24
|
+
keys.each do |key|
|
|
25
|
+
if hash[key].kind_of? Hash
|
|
26
|
+
new_hash[key] = get_values(index, hash[key].keys, hash[key])
|
|
27
|
+
else
|
|
28
|
+
new_hash[key] = hash[key][index]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
return new_hash
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module DaFace
|
|
2
|
+
module Datasift
|
|
3
|
+
class Parser
|
|
4
|
+
include DaFace::Utilities
|
|
5
|
+
|
|
6
|
+
def build_object data
|
|
7
|
+
DaFace::Datasift::DaObject.new data
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def build_objects data
|
|
11
|
+
objects = []
|
|
12
|
+
data[:interactions].each do |object_data|
|
|
13
|
+
objects << build_object(object_data)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
return objects
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def parse_collection json=nil
|
|
20
|
+
raise DaFace::Datasift::MissingJson unless json
|
|
21
|
+
|
|
22
|
+
data = JSON.parse(json)
|
|
23
|
+
symbolized_data = symbolize_keys(data.keys, data)
|
|
24
|
+
return build_objects(symbolized_data)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def parse_from_json json=nil
|
|
28
|
+
raise DaFace::Datasift::MissingJson unless json
|
|
29
|
+
data = JSON.parse(json)
|
|
30
|
+
symbolized_data = symbolize_keys(data.keys, data)
|
|
31
|
+
return build_object(symbolized_data)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module DaFace
|
|
2
|
+
module Datasift
|
|
3
|
+
class Twitter
|
|
4
|
+
include DaFace::Utilities
|
|
5
|
+
|
|
6
|
+
attr_accessor :retweet, :retweeted, :tweet, :status
|
|
7
|
+
|
|
8
|
+
def self.new data
|
|
9
|
+
if data[:status]
|
|
10
|
+
return DaFace::Datasift::TwitterUserStatus.new(data)
|
|
11
|
+
else
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def initialize data
|
|
17
|
+
if data.keys.include? :retweet
|
|
18
|
+
@tweet = DaFace::Twitter::Parser.parse extract_retweet_info(data), true
|
|
19
|
+
@retweeted = DaFace::Twitter::Parser.parse extract_tweet_info(data), false
|
|
20
|
+
@retweet = true
|
|
21
|
+
else
|
|
22
|
+
@tweet = DaFace::Twitter::Parser.parse extract_tweet_info(data), false
|
|
23
|
+
@retweet = false
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def retweet?
|
|
28
|
+
@retweet
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
def extract_retweet_info data
|
|
33
|
+
data[:retweet].merge({:text => data[:retweeted][:text]})
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def extract_tweet_info data
|
|
37
|
+
if data[:retweet]
|
|
38
|
+
data[:retweeted]
|
|
39
|
+
else
|
|
40
|
+
data
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module DaFace
|
|
2
|
+
module Datasift
|
|
3
|
+
class TwitterDeleteNotification
|
|
4
|
+
attr_reader :interaction_id, :interaction_type, :tweet_id
|
|
5
|
+
|
|
6
|
+
def initialize data={}
|
|
7
|
+
raise DaFace::Datasift::BadTwitterDeleteNotification.new('Missing interaction information') unless data[:interaction]
|
|
8
|
+
raise DaFace::Datasift::BadTwitterDeleteNotification.new('Missing twitter information') unless data[:interaction]
|
|
9
|
+
|
|
10
|
+
@interaction_id = data[:interaction][:id]
|
|
11
|
+
@interaction_type = data[:interaction][:type]
|
|
12
|
+
@tweet_id = data[:twitter][:id]
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module DaFace
|
|
2
|
+
module Datasift
|
|
3
|
+
class TwitterUserStatus
|
|
4
|
+
STATUS_PROTECT = :user_protect
|
|
5
|
+
STATUS_UNPROTECT = :user_unprotect
|
|
6
|
+
STATUS_SUSPEND = :user_suspend
|
|
7
|
+
STATUS_UNSUSPEND = :user_unsuspend
|
|
8
|
+
STATUS_DELETE = :user_delete
|
|
9
|
+
STATUS_UNDELETE = :user_undelete
|
|
10
|
+
|
|
11
|
+
attr_reader :user_id, :status
|
|
12
|
+
|
|
13
|
+
def initialize data={}
|
|
14
|
+
@user_id = data[:user][:id]
|
|
15
|
+
set_status! data[:status]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
def set_status! status
|
|
20
|
+
case status
|
|
21
|
+
when 'user_protect'
|
|
22
|
+
@status = STATUS_PROTECT
|
|
23
|
+
when 'user_unprotect'
|
|
24
|
+
@status = STATUS_UNPROTECT
|
|
25
|
+
when 'user_suspend'
|
|
26
|
+
@status = STATUS_SUSPEND
|
|
27
|
+
when 'user_unsuspend'
|
|
28
|
+
@status = STATUS_UNSUSPEND
|
|
29
|
+
when 'user_delete'
|
|
30
|
+
@status = STATUS_DELETE
|
|
31
|
+
when 'user_undelete'
|
|
32
|
+
@status = STATUS_UNDELETE
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module DaFace
|
|
2
|
+
module Twitter
|
|
3
|
+
class Parser
|
|
4
|
+
extend DaFace::Utilities
|
|
5
|
+
|
|
6
|
+
def self.parse data, retweet=false
|
|
7
|
+
parsed_data = symbolize_keys(data.keys, data)
|
|
8
|
+
|
|
9
|
+
user = DaFace::Twitter::User.new parsed_data[:user]
|
|
10
|
+
tweet = DaFace::Twitter::Tweet.new parsed_data.merge({:user => user, :retweet => retweet})
|
|
11
|
+
return tweet
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module DaFace
|
|
2
|
+
module Twitter
|
|
3
|
+
class Tweet
|
|
4
|
+
include DaFace::Utilities
|
|
5
|
+
|
|
6
|
+
attr_reader :id, :user, :created_at, :lang, :text, :source, :links,
|
|
7
|
+
:retweet, :retweet_count
|
|
8
|
+
|
|
9
|
+
def initialize data={}
|
|
10
|
+
allowed_attributes.each do |attr|
|
|
11
|
+
unless data[attr].nil?
|
|
12
|
+
self.instance_variable_set("@#{attr}".to_sym, data[attr])
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
normalize_attributes!
|
|
16
|
+
return self
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def retweet?
|
|
20
|
+
@retweet || false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def retweet_count
|
|
24
|
+
@retweet_count || 0
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def id_str
|
|
28
|
+
@id.to_s
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def normalize_attributes!
|
|
32
|
+
@created_at = parse_timestamp(@created_at) if @created_at
|
|
33
|
+
@links = parse_links(@links) if @links
|
|
34
|
+
@id = @id.to_i if @id
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def allowed_attributes
|
|
38
|
+
[:id, :user, :created_at, :lang, :text, :source, :links,
|
|
39
|
+
:retweet, :retweet_count]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
def parse_links links
|
|
44
|
+
return [] unless links
|
|
45
|
+
links.collect{|l| parse_uri(l)}
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module DaFace
|
|
2
|
+
module Twitter
|
|
3
|
+
class User
|
|
4
|
+
include DaFace::Utilities
|
|
5
|
+
|
|
6
|
+
attr_reader :id, :created_at, :favourites_count, :friends_count, :geo_enabled,
|
|
7
|
+
:lang, :listed_count, :name, :profile_image_url, :profile_image_url_https,
|
|
8
|
+
:screen_name, :statuses_count, :verified
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def initialize data={}
|
|
12
|
+
self.allowed_attributes.each do |attr|
|
|
13
|
+
unless data[attr].nil?
|
|
14
|
+
self.instance_variable_set("@#{attr}", data[attr])
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
self.normalize_attributes!
|
|
18
|
+
return self
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def allowed_attributes
|
|
22
|
+
[:id, :created_at, :favourites_count, :friends_count, :geo_enabled,
|
|
23
|
+
:lang, :listed_count, :name, :profile_image_url, :profile_image_url_https,
|
|
24
|
+
:screen_name, :statuses_count, :verified]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def normalize_attributes!
|
|
28
|
+
@created_at = parse_timestamp(@created_at) if @created_at
|
|
29
|
+
@profile_image_url = parse_uri(@profile_image_url) if @profile_image_url
|
|
30
|
+
@profile_image_url_https = parse_uri(@profile_image_url_https) if @profile_image_url_https
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def favourites_count
|
|
34
|
+
@favourites_count || 0
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def favorites_count
|
|
38
|
+
favourites_count
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def friends_count
|
|
42
|
+
@friends_count || 0
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def listed_count
|
|
46
|
+
@listed_count
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def id_str
|
|
50
|
+
@id.to_s
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module DaFace
|
|
2
|
+
module Utilities
|
|
3
|
+
|
|
4
|
+
# Creates a new hash with all keys as symbols, can be
|
|
5
|
+
# any level of depth
|
|
6
|
+
def symbolize_keys keys, hash
|
|
7
|
+
new_hash = {}
|
|
8
|
+
keys.each do |key|
|
|
9
|
+
if hash[key].kind_of? Hash
|
|
10
|
+
new_hash[key.to_sym] = symbolize_keys(hash[key].keys, hash[key])
|
|
11
|
+
elsif hash[key].kind_of? Array
|
|
12
|
+
new_hash[key.to_sym] = []
|
|
13
|
+
hash[key].each do |item|
|
|
14
|
+
if item.kind_of? Hash
|
|
15
|
+
new_hash[key.to_sym] << symbolize_keys(item.keys, item)
|
|
16
|
+
else
|
|
17
|
+
new_hash[key.to_sym] << item
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
else
|
|
21
|
+
new_hash[key.to_sym] = hash[key]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
return new_hash
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def parse_uri url
|
|
29
|
+
URI(url) if url
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def parse_timestamp timestamp=nil
|
|
33
|
+
return nil unless timestamp
|
|
34
|
+
return Time.at(timestamp) if timestamp.kind_of? Fixnum
|
|
35
|
+
return Time.at(timestamp) if timestamp.kind_of? Float
|
|
36
|
+
return Time.parse(timestamp) if timestamp.kind_of? String
|
|
37
|
+
return timestamp
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/da_face.rb
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Internals dependencies
|
|
2
|
+
require "da_face/version"
|
|
3
|
+
require "da_face/configuration"
|
|
4
|
+
require "da_face/utilities"
|
|
5
|
+
require "da_face/errors"
|
|
6
|
+
require "da_face/api/adapter"
|
|
7
|
+
require "da_face/api/adapters/base"
|
|
8
|
+
require "da_face/api/adapters/excon_adapter"
|
|
9
|
+
require "da_face/api/adapters/em_http_request_adapter"
|
|
10
|
+
require "da_face/api/push"
|
|
11
|
+
require "da_face/api/push_log"
|
|
12
|
+
require "da_face/api/push_log_entry"
|
|
13
|
+
require "da_face/api/push_subscription"
|
|
14
|
+
require "da_face/datasift/parser"
|
|
15
|
+
require "da_face/datasift/errors"
|
|
16
|
+
require "da_face/datasift/da_object"
|
|
17
|
+
require "da_face/datasift/interaction"
|
|
18
|
+
require "da_face/datasift/links"
|
|
19
|
+
require "da_face/datasift/link"
|
|
20
|
+
require "da_face/datasift/demographic"
|
|
21
|
+
require "da_face/datasift/language"
|
|
22
|
+
require "da_face/datasift/salience"
|
|
23
|
+
require "da_face/datasift/twitter"
|
|
24
|
+
require "da_face/datasift/twitter_delete_notification"
|
|
25
|
+
require "da_face/datasift/twitter_user_status"
|
|
26
|
+
require "da_face/twitter/parser"
|
|
27
|
+
require "da_face/twitter/tweet"
|
|
28
|
+
require "da_face/twitter/user"
|
|
29
|
+
|
|
30
|
+
# External dependencies
|
|
31
|
+
require "json"
|
|
32
|
+
require "excon"
|
|
33
|
+
|
|
34
|
+
module DaFace
|
|
35
|
+
class << self
|
|
36
|
+
attr_accessor :configuration
|
|
37
|
+
|
|
38
|
+
def configuration
|
|
39
|
+
@configuration ||= Configuration.new
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def configure
|
|
43
|
+
yield(configuration)
|
|
44
|
+
self.configuration
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def reset_config
|
|
48
|
+
@configuration = Configuration.new
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def create_subscription data={}
|
|
52
|
+
DaFace::Api::PushSubscription.new data
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def parse_datasift_collection data
|
|
56
|
+
DaFace::Datasift::Parser.new.parse_collection(data)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def parse_datasift_object data
|
|
60
|
+
DaFace::Datasift::Parser.new.parse_from_json(data)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def get_subscriptions
|
|
64
|
+
DaFace::Api::PushSubscription.get_all
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe DaFace::Api::Adapter do
|
|
4
|
+
before do
|
|
5
|
+
DaFace.configure do |config|
|
|
6
|
+
config.api_path_prefix = '/lolcat'
|
|
7
|
+
config.api_host = 'http://host.com'
|
|
8
|
+
config.user = 'lol'
|
|
9
|
+
config.api_key = 'cat'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe '#get' do
|
|
14
|
+
before do
|
|
15
|
+
@adapter = DaFace::Api::Adapter.new
|
|
16
|
+
@excon_adapter = DaFace::Api::Adapters::ExconAdapter.new
|
|
17
|
+
@conn = Excon.new 'http://something.com', :mock => true
|
|
18
|
+
Excon.stub({}, {:body => {'ok' => true}.to_json, :status => 200})
|
|
19
|
+
allow(@excon_adapter).to receive(:connection).and_return(@conn)
|
|
20
|
+
allow(@adapter).to receive(:connection).and_return(@excon_adapter)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'performs a get' do
|
|
24
|
+
expect(@adapter.get('thing')).to eq({:ok => true})
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe '#put' do
|
|
29
|
+
before do
|
|
30
|
+
@adapter = DaFace::Api::Adapter.new
|
|
31
|
+
@excon_adapter = DaFace::Api::Adapters::ExconAdapter.new
|
|
32
|
+
@conn = Excon.new 'http://something.com/post', :mock => true
|
|
33
|
+
Excon.stub({}, {:status => 200})
|
|
34
|
+
allow(@excon_adapter).to receive(:connection).and_return(@conn)
|
|
35
|
+
allow(@adapter).to receive(:connection).and_return(@excon_adapter)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'performs a post' do
|
|
39
|
+
expect(@adapter.put('thing', {:something => 1})).to eq(true)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe '#post' do
|
|
44
|
+
before do
|
|
45
|
+
@adapter = DaFace::Api::Adapter.new
|
|
46
|
+
@excon_adapter = DaFace::Api::Adapters::ExconAdapter.new
|
|
47
|
+
@conn = Excon.new 'http://something.com', :mock => true
|
|
48
|
+
Excon.stub({}, {:status => 200})
|
|
49
|
+
allow(@excon_adapter).to receive(:connection).and_return(@conn)
|
|
50
|
+
allow(@adapter).to receive(:connection).and_return(@excon_adapter)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'performs a put' do
|
|
54
|
+
expect(@adapter.post('thing', {:something => 1})).to eq(true)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|