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.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +51 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +114 -0
  9. data/Rakefile +2 -0
  10. data/da_face.gemspec +27 -0
  11. data/lib/da_face/api/adapter.rb +42 -0
  12. data/lib/da_face/api/adapters/base.rb +59 -0
  13. data/lib/da_face/api/adapters/em_http_request_adapter.rb +8 -0
  14. data/lib/da_face/api/adapters/excon_adapter.rb +33 -0
  15. data/lib/da_face/api/core.rb +0 -0
  16. data/lib/da_face/api/push.rb +77 -0
  17. data/lib/da_face/api/push_log.rb +11 -0
  18. data/lib/da_face/api/push_log_entry.rb +15 -0
  19. data/lib/da_face/api/push_subscription.rb +141 -0
  20. data/lib/da_face/configuration.rb +11 -0
  21. data/lib/da_face/datasift/da_object.rb +35 -0
  22. data/lib/da_face/datasift/demographic.rb +12 -0
  23. data/lib/da_face/datasift/errors.rb +9 -0
  24. data/lib/da_face/datasift/interaction.rb +33 -0
  25. data/lib/da_face/datasift/language.rb +14 -0
  26. data/lib/da_face/datasift/link.rb +34 -0
  27. data/lib/da_face/datasift/links.rb +38 -0
  28. data/lib/da_face/datasift/parser.rb +35 -0
  29. data/lib/da_face/datasift/salience.rb +16 -0
  30. data/lib/da_face/datasift/twitter.rb +46 -0
  31. data/lib/da_face/datasift/twitter_delete_notification.rb +16 -0
  32. data/lib/da_face/datasift/twitter_user_status.rb +37 -0
  33. data/lib/da_face/errors.rb +7 -0
  34. data/lib/da_face/twitter/parser.rb +16 -0
  35. data/lib/da_face/twitter/tweet.rb +49 -0
  36. data/lib/da_face/twitter/user.rb +55 -0
  37. data/lib/da_face/utilities.rb +41 -0
  38. data/lib/da_face/version.rb +3 -0
  39. data/lib/da_face.rb +69 -0
  40. data/spec/da_face/api/adapter_spec.rb +58 -0
  41. data/spec/da_face/api/adapters/base_spec.rb +125 -0
  42. data/spec/da_face/api/push_log_spec.rb +34 -0
  43. data/spec/da_face/api/push_spec.rb +108 -0
  44. data/spec/da_face/api/push_subscription_spec.rb +220 -0
  45. data/spec/da_face/configuration_spec.rb +15 -0
  46. data/spec/da_face/datasift/da_object_spec.rb +191 -0
  47. data/spec/da_face/datasift/demographic_spec.rb +30 -0
  48. data/spec/da_face/datasift/interaction_spec.rb +93 -0
  49. data/spec/da_face/datasift/language_spec.rb +45 -0
  50. data/spec/da_face/datasift/link_spec.rb +80 -0
  51. data/spec/da_face/datasift/links_spec.rb +70 -0
  52. data/spec/da_face/datasift/parser_spec.rb +5 -0
  53. data/spec/da_face/datasift/salience_spec.rb +33 -0
  54. data/spec/da_face/datasift/twitter_delete_notification_spec.rb +45 -0
  55. data/spec/da_face/datasift/twitter_spec.rb +56 -0
  56. data/spec/da_face/datasift/twitter_user_status_spec.rb +36 -0
  57. data/spec/da_face/twitter/parser_spec.rb +16 -0
  58. data/spec/da_face/twitter/tweet_spec.rb +77 -0
  59. data/spec/da_face/twitter/user_spec.rb +116 -0
  60. data/spec/da_face/utilities_spec.rb +74 -0
  61. data/spec/da_face_spec.rb +120 -0
  62. data/spec/fixtures/api_responses/get_subscriptions.json +26 -0
  63. data/spec/fixtures/api_responses/log.json +126 -0
  64. data/spec/fixtures/api_responses/validate_success.json +4 -0
  65. data/spec/fixtures/demographic/simple.json +5 -0
  66. data/spec/fixtures/interaction/simple.json +28 -0
  67. data/spec/fixtures/interactions/collection.json +1 -0
  68. data/spec/fixtures/interactions/simple.json +102 -0
  69. data/spec/fixtures/language/simple.json +5 -0
  70. data/spec/fixtures/links/multiples.json +69 -0
  71. data/spec/fixtures/links/simple.json +65 -0
  72. data/spec/fixtures/links/simple_failing.json +65 -0
  73. data/spec/fixtures/notifications/delete.json +10 -0
  74. data/spec/fixtures/notifications/user_delete.json +16 -0
  75. data/spec/fixtures/notifications/user_protect.json +16 -0
  76. data/spec/fixtures/notifications/user_suspend.json +16 -0
  77. data/spec/fixtures/notifications/user_undelete.json +16 -0
  78. data/spec/fixtures/notifications/user_unprotect.json +16 -0
  79. data/spec/fixtures/notifications/user_unsuspend.json +16 -0
  80. data/spec/fixtures/salience/simple.json +5 -0
  81. data/spec/fixtures/twitter/retweet.json +70 -0
  82. data/spec/fixtures/twitter/simple.json +33 -0
  83. data/spec/integration/stress_spec.rb +16 -0
  84. data/spec/spec_helper.rb +23 -0
  85. data/spec/test_spec.rb +7 -0
  86. metadata +259 -0
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe DaFace::Twitter::User do
4
+ before do
5
+ @parser = DaFace::Datasift::Parser.new
6
+ fixture = json_fixture('twitter/simple.json')['user']
7
+ @data = @parser.symbolize_keys(fixture.keys, fixture)
8
+ end
9
+
10
+ describe '#new' do
11
+ it 'creates a User object' do
12
+ obj = DaFace::Twitter::User.new @data
13
+
14
+ expect(obj.class).to eq(DaFace::Twitter::User)
15
+ end
16
+ end
17
+
18
+ describe 'attributes' do
19
+ before do
20
+ @user = DaFace::Twitter::User.new @data
21
+ end
22
+
23
+ describe '#id' do
24
+ it 'is preset' do
25
+ expect(@user.id).to eq(@data[:id])
26
+ end
27
+ end
28
+
29
+ describe '#id_str' do
30
+ it 'is present' do
31
+ expect(@user.id_str).to eq(@data[:id].to_s)
32
+ end
33
+ end
34
+
35
+ describe '#created_at' do
36
+ it 'is present' do
37
+ expect(@user.created_at).to eq(Time.parse(@data[:created_at]))
38
+ end
39
+ end
40
+
41
+ describe '#favourites_count' do
42
+ it 'is present' do
43
+ expect(@user.favourites_count).to eq(@data[:favourites_count])
44
+ end
45
+ end
46
+
47
+ describe '#favorites_count' do
48
+ it 'is present' do
49
+ expect(@user.favorites_count).to eq(@user.favourites_count)
50
+ end
51
+ end
52
+
53
+ describe '#friends_count' do
54
+ it 'is present' do
55
+ expect(@user.friends_count).to eq(@data[:friends_count])
56
+ end
57
+ end
58
+
59
+ describe '#geo_enabled' do
60
+ it 'is present' do
61
+ expect(@user.geo_enabled).to eq(@data[:geo_enabled])
62
+ end
63
+ end
64
+
65
+ describe '#lang' do
66
+ it 'is present' do
67
+ expect(@user.lang).to eq(@data[:lang])
68
+ end
69
+ end
70
+
71
+ describe '#listed_count' do
72
+ it 'is present' do
73
+ expect(@user.listed_count).to eq(@data[:listed_count])
74
+ end
75
+ end
76
+
77
+ describe '#name' do
78
+ it 'is present' do
79
+ expect(@user.name).to eq(@data[:name])
80
+ end
81
+ end
82
+
83
+ describe '#profile_image_url' do
84
+ it 'is present' do
85
+ expect(@user.profile_image_url.kind_of?(URI)).to eq(true)
86
+ expect(@user.profile_image_url).to eq(URI(@data[:profile_image_url]))
87
+ end
88
+ end
89
+
90
+ describe '#profile_image_url_https' do
91
+ it 'is present' do
92
+ expect(@user.profile_image_url_https.kind_of?(URI)).to eq(true)
93
+ expect(@user.profile_image_url_https).to eq(URI(@data[:profile_image_url_https]))
94
+ end
95
+ end
96
+
97
+ describe '#screen_name' do
98
+ it 'is present' do
99
+ expect(@user.screen_name).to eq(@data[:screen_name])
100
+ end
101
+ end
102
+
103
+ describe '#statuses_count' do
104
+ it 'is present' do
105
+ expect(@user.statuses_count).to eq(@data[:statuses_count])
106
+ end
107
+ end
108
+
109
+ describe '#verified' do
110
+ it 'is present' do
111
+ expect(@user.verified).to eq(@data[:verified])
112
+ end
113
+ end
114
+
115
+ end
116
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe DaFace::Utilities do
4
+ before do
5
+ @utilities = Object.new
6
+ @utilities.extend(DaFace::Utilities)
7
+ end
8
+
9
+ describe '#symbolize_keys' do
10
+ before do
11
+ @hash = {
12
+ 'key8' => ['8.1', '8.2'],
13
+ 'key9' => [['9.1']],
14
+ 'key1' => '1',
15
+ 'key2' => [{'key3' => '3'},
16
+ {'key7' => '7'}],
17
+ 'key4' => {'key5' => {'key6' => '6'}}}
18
+
19
+ @expected = {
20
+ :key8 => ['8.1', '8.2'],
21
+ :key9 => [['9.1']],
22
+ :key1 => '1',
23
+ :key2 => [{:key3 => '3'},
24
+ {:key7 => '7'}],
25
+ :key4 => {:key5 => {:key6 => '6'}}}
26
+ end
27
+
28
+ it 'converts hash keys to symbols even in depth' do
29
+ expect(@utilities.symbolize_keys(@hash.keys, @hash)).to eq(@expected)
30
+ end
31
+ end
32
+
33
+ describe '#parse_uri' do
34
+ it 'converts string url into URI object' do
35
+ url = 'http://someuri.com/somepath?something=thing'
36
+ expect(@utilities.parse_uri(url).kind_of?(URI)).to eq(true)
37
+ expect(@utilities.parse_uri(url).to_s).to eq(url)
38
+ end
39
+ end
40
+
41
+ describe '#parse_timestamp' do
42
+ it 'converts fixnum timestam to Time object' do
43
+ time = Time.parse('Fri, 16 May 2014 00:24:08 +0000')
44
+ expect(@utilities.parse_timestamp(time.to_i)).to eq(time)
45
+ end
46
+
47
+ it 'returns nil if nothing given' do
48
+ expect(@utilities.parse_timestamp).to eq(nil)
49
+ end
50
+
51
+ it 'returns nil if nil given' do
52
+ expect(@utilities.parse_timestamp(nil)).to eq(nil)
53
+ end
54
+
55
+ it 'parses a string date time to Time object' do
56
+ time = 'Fri, 16 May 2014 00:24:08 +0000'
57
+ expect(@utilities.parse_timestamp(time)).to eq(Time.parse(time))
58
+ end
59
+
60
+ it 'converts float to Time object' do
61
+ time = 1400199848.5762
62
+ expect(@utilities.parse_timestamp(time)).to eq(Time.at(time))
63
+ end
64
+
65
+ it 'returns what it gets if not recognized' do
66
+ time = Time.now
67
+ something = Object.new
68
+ expect(@utilities.parse_timestamp(time)).to eq(time)
69
+ expect(@utilities.parse_timestamp(something)).to eq(something)
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,120 @@
1
+ require 'spec_helper'
2
+
3
+ describe DaFace do
4
+ describe '#create_subscription' do
5
+ before do
6
+ @attrs = {
7
+ :output_type => "http",
8
+ :name => "SomeName",
9
+ :hash => "l3k4j23k4jl23j42l3k4j2l3kj4k3j4l",
10
+ :output_params => {
11
+ :auth => {
12
+ :type => 'none'
13
+ },
14
+ :max_size => 2097152,
15
+ :delivery_frequency => 0,
16
+ :url => "http =>//someurl.com/someendpoint"
17
+ },
18
+ :start => 1412345259,
19
+ :end => 1412375259
20
+ }
21
+ end
22
+
23
+ it 'creates a PushSubscription with data' do
24
+ obj = DaFace.create_subscription @attrs
25
+ expect(obj.class).to eq(DaFace::Api::PushSubscription)
26
+ end
27
+
28
+ it 'creates empty PushSubscription' do
29
+ obj = DaFace.create_subscription
30
+ expect(obj.class).to eq(DaFace::Api::PushSubscription)
31
+ end
32
+ end
33
+
34
+ describe '#parse_datasift_collection' do
35
+ before do
36
+ @data = fixture('interactions/collection.json')
37
+ end
38
+
39
+ it 'parses a collection of Datasift objects' do
40
+ expect(Proc.new{@result = DaFace.parse_datasift_collection(@data)}).not_to raise_error
41
+ expect(@result.class).to eq(Array)
42
+ expect(@result.size).not_to eq(0)
43
+ end
44
+ end
45
+
46
+ describe '#parse_datasift_object' do
47
+ before do
48
+ @data = fixture('interactions/simple.json')
49
+ end
50
+
51
+ it 'parses a single Datasift object' do
52
+ expect(Proc.new{@result = DaFace.parse_datasift_object(@data)}).not_to raise_error
53
+ expect(@result.class).to eq(DaFace::Datasift::DaObject)
54
+ end
55
+ end
56
+
57
+ describe '#get_subscriptions' do
58
+ before do
59
+ DaFace.configure do |config|
60
+ config.api_path_prefix = '/lolcat'
61
+ config.api_host = 'http://host.com'
62
+ config.user = 'lol'
63
+ config.api_key = 'cat'
64
+ end
65
+ @adapter = DaFace::Api::Adapter.new
66
+ @excon_adapter = DaFace::Api::Adapters::ExconAdapter.new
67
+ @conn = Excon.new 'http://host.com/lolcat', :mock => true
68
+ allow(@excon_adapter).to receive(:connection).and_return(@conn)
69
+ allow(@adapter).to receive(:connection).and_return(@excon_adapter)
70
+ allow(DaFace::Api::Push).to receive(:connection).and_return(@adapter)
71
+ Excon.stub({:path => '/push/get'},
72
+ {:body => json_fixture('api_responses/get_subscriptions.json').to_json, :status => 200})
73
+ end
74
+
75
+ it 'fetches subscriptions' do
76
+ expect(Proc.new{@result = DaFace.get_subscriptions}).not_to raise_error
77
+ expect(@result.class).to eq(Array)
78
+ expect(@result.size).not_to eq(0)
79
+ end
80
+ end
81
+
82
+ describe '#reset_config' do
83
+ before do
84
+ DaFace.configure do |config|
85
+ config.user = 'someone'
86
+ end
87
+ end
88
+
89
+ it 'resets configuration to default' do
90
+ DaFace.reset_config
91
+ expect(DaFace.configuration.user).to eq(nil)
92
+ end
93
+ end
94
+
95
+ describe '#configure' do
96
+ before do
97
+ DaFace.configure do |config|
98
+ config.api_path_prefix = 'api'
99
+ config.api_host = 'something'
100
+ config.user = 'someone'
101
+ config.api_key = 'some key'
102
+ end
103
+ end
104
+ it 'sets configuration' do
105
+ expect(DaFace.configuration.api_path_prefix).to eq('api')
106
+ expect(DaFace.configuration.api_host).to eq('something')
107
+ expect(DaFace.configuration.user).to eq('someone')
108
+ expect(DaFace.configuration.api_key).to eq('some key')
109
+ end
110
+
111
+ it 'returns configuration' do
112
+ obj = DaFace.configure do |config|
113
+ config.user = 'someone'
114
+ end
115
+
116
+ expect(obj.class).to eq(DaFace::Configuration)
117
+ expect(obj).to eq(DaFace.configuration)
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,26 @@
1
+ {
2
+ "subscriptions": [
3
+ {
4
+ "id": "9f9s9s8d08f8s0d7g0a7s9d7a09s70g9",
5
+ "output_type": "http",
6
+ "name": "LikeFolioPrimary",
7
+ "created_at": 1412345259,
8
+ "user_id": 28949,
9
+ "hash": "a0s9d8a09s8da09sd8a9sd08as9d8a0s",
10
+ "hash_type": "stream",
11
+ "output_params": {
12
+ "max_size": 2097152,
13
+ "delivery_frequency": 0,
14
+ "url": "http://somewhere.com/someapi"
15
+ },
16
+ "status": "active",
17
+ "last_request": 1412622810,
18
+ "last_success": 1412622796,
19
+ "remaining_bytes": null,
20
+ "lost_data": false,
21
+ "start": 1412345259,
22
+ "end": null
23
+ }
24
+ ],
25
+ "count": 1
26
+ }
@@ -0,0 +1,126 @@
1
+ {
2
+ "success": true,
3
+ "count": 201,
4
+ "log_entries": [
5
+ {
6
+ "request_time": 1412423348,
7
+ "success": true,
8
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
9
+ "message": "Successfully delivered after delivery failure(s)"
10
+ },
11
+ {
12
+ "request_time": 1412423345,
13
+ "success": false,
14
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
15
+ "message": "The endpoint returned a 500 internal server error"
16
+ },
17
+ {
18
+ "request_time": 1412423337,
19
+ "success": false,
20
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
21
+ "message": "The endpoint returned a 500 internal server error"
22
+ },
23
+ {
24
+ "request_time": 1412423328,
25
+ "success": true,
26
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
27
+ "message": "Successfully delivered after delivery failure(s)"
28
+ },
29
+ {
30
+ "request_time": 1412423300,
31
+ "success": false,
32
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
33
+ "message": "The endpoint returned a 500 internal server error"
34
+ },
35
+ {
36
+ "request_time": 1412423289,
37
+ "success": true,
38
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
39
+ "message": "Successfully delivered after delivery failure(s)"
40
+ },
41
+ {
42
+ "request_time": 1412423288,
43
+ "success": false,
44
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
45
+ "message": "The endpoint returned a 500 internal server error"
46
+ },
47
+ {
48
+ "request_time": 1412423278,
49
+ "success": true,
50
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
51
+ "message": "Successfully delivered after delivery failure(s)"
52
+ },
53
+ {
54
+ "request_time": 1412423276,
55
+ "success": false,
56
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
57
+ "message": "The endpoint returned a 500 internal server error"
58
+ },
59
+ {
60
+ "request_time": 1412423239,
61
+ "success": true,
62
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
63
+ "message": "Successfully delivered after delivery failure(s)"
64
+ },
65
+ {
66
+ "request_time": 1412423230,
67
+ "success": false,
68
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
69
+ "message": "The endpoint returned a 500 internal server error"
70
+ },
71
+ {
72
+ "request_time": 1412423223,
73
+ "success": false,
74
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
75
+ "message": "The endpoint returned a 500 internal server error"
76
+ },
77
+ {
78
+ "request_time": 1412423183,
79
+ "success": true,
80
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
81
+ "message": "Successfully delivered after delivery failure(s)"
82
+ },
83
+ {
84
+ "request_time": 1412423171,
85
+ "success": false,
86
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
87
+ "message": "The endpoint returned a 500 internal server error"
88
+ },
89
+ {
90
+ "request_time": 1412423164,
91
+ "success": false,
92
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
93
+ "message": "The endpoint returned a 500 internal server error"
94
+ },
95
+ {
96
+ "request_time": 1412423147,
97
+ "success": true,
98
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
99
+ "message": "Successfully delivered after delivery failure(s)"
100
+ },
101
+ {
102
+ "request_time": 1412423117,
103
+ "success": false,
104
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
105
+ "message": "The endpoint returned a 500 internal server error"
106
+ },
107
+ {
108
+ "request_time": 1412423105,
109
+ "success": true,
110
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
111
+ "message": "Successfully delivered after delivery failure(s)"
112
+ },
113
+ {
114
+ "request_time": 1412423104,
115
+ "success": false,
116
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
117
+ "message": "The endpoint returned a 500 internal server error"
118
+ },
119
+ {
120
+ "request_time": 1412423090,
121
+ "success": true,
122
+ "subscription_id": "0a0s0s9d0s90s9d0a9s0d9s09d0a9s09",
123
+ "message": "Successfully delivered after delivery failure(s)"
124
+ }
125
+ ]
126
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "success": true,
3
+ "message": "Validated successfully"
4
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "demographic": {
3
+ "gender": "male"
4
+ }
5
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "author": {
3
+ "avatar": "http://lolcat.com/somelolimage.jpeg",
4
+ "id": 12345678,
5
+ "language": "en",
6
+ "link": "http://somesite.com/someuser",
7
+ "name": "Some User",
8
+ "username": "TheStockHerald"
9
+ },
10
+ "content": "$TRLA: 6:24 pm Trulia announces it is experiencing record levels of consumer ... http://t.co/HzINHMznR8",
11
+ "created_at": "Fri, 16 May 2014 00:24:08 +0000",
12
+ "id": "1e3dc90650d0a400e074adecd126164a",
13
+ "link": "http://twitter.com/TheStockHerald/status/467098134435221504",
14
+ "received_at": 1400199848.5762,
15
+ "schema": {
16
+ "version": 3
17
+ },
18
+ "source": "dlvr.it",
19
+ "type": "twitter",
20
+ "tags": [
21
+ "trader"
22
+ ],
23
+ "tag_tree": {
24
+ "sentiment_score": 700,
25
+ "quality_score": 950
26
+ }
27
+
28
+ }