datasift 2.0.4 → 2.1.0.beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- data.tar.gz: 39c802a214147e3719a2515ca3de7cbdf0aac410
4
- metadata.gz: 000329ea9766929bd49de5c246fbc145e4eea595
5
2
  SHA512:
6
- data.tar.gz: ab1a7dab1880c639e5fbce11a72a2b70445d2f1f057fe43d7a48f8ba8f30d412500d993fce4e2edd08cbd98003dabe4a8decf3c82a3de0273e323e0f6ff1b07e
7
- metadata.gz: e4dc436e565ee2b2e34dfb18aa2e7c8e2b30fb2065af25a496ca0424504baaa22e9e0bfa638ab04e92ce92b35021d0f8abb249fed39bdf135fc6b3da1e0b0ff5
3
+ metadata.gz: 02bf11099c9d26f748777eb250a2012e6ca492f03ea6463f15f0dacae1f6881452254ddd7b7e6328c8d4118b0f5ea6c4cf29d72db1d0cca83c6f373ff4248f2e
4
+ data.tar.gz: a81b1b1f678cf752e7178954d805f8389e4ffd022cb080abc34c3d448ab6290e38493800265a809b9a75355f60d1812ff9d5b4e17ecabc5350fc73614c7df762
5
+ SHA1:
6
+ metadata.gz: bf41f27515af94fb037c2525301e1a731c5e2416
7
+ data.tar.gz: 98567da3573cccd91e78618ef0ad65744c871016
data/README.md CHANGED
@@ -55,6 +55,7 @@ more details.
55
55
 
56
56
  Changelog
57
57
  ---------
58
+ * v.2.1.0.beta Adding Managed Sources support. Thanks to [giovannelli](https://github.com/giovannelli) for the contribution (2013-08-05)
58
59
 
59
60
  * v.2.0.4 Bug fix to handle HTTP 202 response codes (2013-03-18)
60
61
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.4
1
+ 2.1.0.beta
data/datasift.gemspec CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.version = File.open('VERSION').first
7
7
 
8
8
  s.authors = ['DataSift']
9
- s.email = ['support@datasift.net']
9
+ s.email = ['support@datasift.com']
10
10
  s.description = %q{The official Ruby library for accessing the DataSift API. See http://datasift.com/ for full details and to sign up for an account.}
11
11
  s.summary = %q{DataSift is a simple wrapper for the DataSift API.}
12
12
  s.homepage = 'http://github.com/datasift/datasift-ruby'
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_runtime_dependency('rest-client', '~> 1.6.3')
19
19
  s.add_runtime_dependency('yajl-ruby', '~> 1.1.0')
20
+ s.add_runtime_dependency('json', '~> 1.5.4')
20
21
  s.add_development_dependency('rdoc', '> 0')
21
22
  s.add_development_dependency('shoulda', '~> 2.11.3')
22
23
  s.add_development_dependency('rspec', '~> 2.6.0')
@@ -0,0 +1,231 @@
1
+ require 'json'
2
+ ### Usage ###
3
+ # user = DataSift::User.new(config['username'], config['api_key'])
4
+ # user.createManagedSource(:token => "CAAIUKbXn8xsBAILlxGCZADEZAM87tRqJXo9OqWskCs6jej3wfQ1LRRZAgHJQEZCHU0ABBXDwiq9o7D4uytC5LpsAcx7oiDusagsJiKtmPaZBeMkuGh4jYt1zsXo4EQuZCWPcZAIdQQLZBtjTpQlbbAZCTuJ4SSrlmOPQZD", :source_type => "facebook_page", :name => "test", :parameters=> {:likes => true, :posts_by_others => true, :comments => true}, :resources => [{ :url => "http://www.facebook.com/theguardian", :title => "The Guardian", :id => 10513336322 } ] )
5
+
6
+ module DataSift
7
+ #The ManagedSource class represents a ManagedSource query.
8
+ class ManagedSource
9
+ #The ID of this Managed Source
10
+ attr_reader :managed_source_id
11
+ #The Managed Source type
12
+ attr_reader :source_type
13
+ #The current status of this Managed Source.
14
+ attr_reader :status
15
+ #The title for this Managed Source.
16
+ attr_reader :name
17
+ #The date/time when this Managed Source was created.
18
+ attr_reader :created_at
19
+ #The Managed Source source_type
20
+ attr_reader :source_type
21
+ #The Managed Source parameters
22
+ attr_reader :parameters
23
+ #The Managed Source resources
24
+ attr_reader :resources
25
+ #The Managed Source token
26
+ attr_reader :token
27
+ #The Managed Source auth
28
+ attr_reader :auth
29
+ #Api raw response
30
+ attr_reader :raw_attributes
31
+
32
+ #Constructor. Pass all parameters to create a new Managed Source, or provide a User object and a managed_source_id to load an existing Managed Source from the API.
33
+ #=== Parameters
34
+ #* +user+ - The DataSift::User object.
35
+ def initialize(user, hash)
36
+ raise InvalidDataError, 'Please supply a valid User object when creating a Managed Source object.' unless user.is_a? DataSift::User
37
+ @user = user
38
+
39
+ if hash.kind_of?(Hash)
40
+ if hash.has_key?('id')
41
+ # Initialising from an array
42
+ @managed_source_id = hash['id']
43
+ initFromArray(hash)
44
+ else
45
+ @source_type = hash[:source_type]
46
+ @name = hash[:name]
47
+ @token = hash[:token]
48
+ @parameters = hash[:parameters]
49
+ @resources = hash[:resources]
50
+ end
51
+ else
52
+ # Fetching from the API
53
+ @managed_source_id = hash
54
+ reloadData()
55
+ end
56
+ end
57
+
58
+ #Get a single Managed Source by ID.
59
+ #=== Parameters
60
+ #* +id+ - The Managed Source ID.
61
+ #=== Returns
62
+ #A ManagedSource object
63
+ def self.get(user, managed_source_id)
64
+ return new(user, user.callAPI('source/get', { 'id' => managed_source_id }))
65
+ end
66
+
67
+ def self.list(user, page = 1, per_page = 20)
68
+ begin
69
+ res = user.callAPI(
70
+ 'source/get', {
71
+ 'page' => page,
72
+ 'max' => per_page
73
+ })
74
+ retval = { 'count' => res['count'], 'managed_sources' => [] }
75
+ for source in res['sources']
76
+ retval['managed_sources'].push(new(user, source))
77
+ end
78
+ retval
79
+ rescue APIError => err
80
+ case err.http_code
81
+ when 400
82
+ #Missing or invalid parameters
83
+ raise InvalidDataError, err
84
+ else
85
+ raise APIError.new(err.http_code), 'Unexpected APIError code: ' + err.http_code.to_s + ' [' + err.message + ']'
86
+ end
87
+ end
88
+ end
89
+
90
+ #Call the DataSift API to create the Managed Source
91
+ def create()
92
+ raise InvalidDataError, 'This Managed Source has already been created' unless not @managed_source_id
93
+
94
+ begin
95
+ res = @user.callAPI(
96
+ 'source/create', {
97
+ 'source_type' => @source_type,
98
+ 'name' => @name,
99
+ 'parameters' => @parameters.to_json,
100
+ 'resources' => @resources.to_json,
101
+ 'auth' => [ 'parameters' => { 'value' => @token } ].to_json
102
+ })
103
+ raise InvalidDataError, 'Prepared successfully but no managed_source_id ID in the response' unless res.has_key?('id')
104
+ @managed_source_id = res['id']
105
+
106
+ rescue APIError => err
107
+ case err.http_code
108
+ when 400
109
+ raise InvalidDataError, err
110
+ else
111
+ raise APIError.new(err.http_code), 'Unexpected APIError code: ' + err.http_code.to_s + ' [' + err.message + ']'
112
+ end
113
+ end
114
+
115
+ # Reload the data so we get the created_at date, initial status and the rest.
116
+ reloadData()
117
+ end
118
+
119
+ #Reload the data for this object from the API.
120
+ def reloadData()
121
+ #Can't do this without a playback ID
122
+ raise InvalidDataError, 'Cannot reload the data with a Managed Source with no Managed Source ID' unless @managed_source_id
123
+
124
+ begin
125
+ initFromArray(@user.callAPI('source/get', { 'id' => @managed_source_id }))
126
+ rescue APIError => err
127
+ case err.http_code
128
+ when 400
129
+ raise InvalidDataError, err
130
+ else
131
+ raise APIError.new(err.http_code), 'Unexpected APIError code: ' + err.http_code.to_s + ' [' + err.message + ']'
132
+ end
133
+ end
134
+ end
135
+
136
+ #Initialise this object from the data in a Hash.
137
+ #=== Parameters
138
+ #* +data+ - The Hash containing the data.
139
+ def initFromArray(data)
140
+ raise APIError, 'No managed source ID in the response' unless data.has_key?('id')
141
+ raise APIError, 'Incorrect managed source ID in the response' unless not @managed_source_id or data['id'] == @managed_source_id
142
+ @managed_source_id = data['id']
143
+
144
+ raise APIError, 'No name in the response' unless data.has_key?('name')
145
+ @name = data['name']
146
+
147
+ raise APIError, 'No auth in the response' unless data.has_key?('auth')
148
+ @auth = data['auth']
149
+
150
+ raise APIError, 'No created at timstamp in the response' unless data.has_key?('created_at')
151
+ @created_at = DateTime.strptime(String(data['created_at']), '%s')
152
+
153
+ raise APIError, 'No status in the response' unless data.has_key?('status')
154
+ @status = data['status']
155
+
156
+ raise APIError, 'No source_type in the response' unless data.has_key?('source_type')
157
+ @source_type = data['source_type']
158
+
159
+ raise APIError, 'No parameters in the response' unless data.has_key?('parameters')
160
+ @parameters = data['parameters']
161
+
162
+ raise APIError, 'No resources in the response' unless data.has_key?('resources')
163
+ @resources = data['resources']
164
+
165
+ @raw_attributes = data
166
+
167
+ return true
168
+ end
169
+
170
+ #Start this Managed Source query.
171
+ def start()
172
+ raise InvalidDataError, 'Cannot start a Managed souce query that hasn\'t been created' unless @managed_source_id
173
+
174
+ begin
175
+ res = @user.callAPI('source/start', { 'id' => @managed_source_id })
176
+ rescue APIError => err
177
+ case err.http_code
178
+ when 400
179
+ # Missing or invalid parameters
180
+ raise InvalidDataError, err
181
+ when 404
182
+ # Managed Source not found
183
+ raise InvalidDataError, err
184
+ else
185
+ raise APIError.new(err.http_code), 'Unexpected APIError code: ' + err.http_code.to_s + ' [' + err.message + ']'
186
+ end
187
+ end
188
+ end
189
+
190
+ #Stop this Managed Source
191
+ def stop()
192
+ raise InvalidDataError, 'Cannot stop a Managed Source query that hasn\'t been prepared' unless @managed_source_id
193
+
194
+ begin
195
+ res = @user.callAPI('source/stop', { 'id' => @managed_source_id })
196
+ rescue APIError => err
197
+ case err.http_code
198
+ when 400
199
+ # Missing or invalid parameters
200
+ raise InvalidDataError, err
201
+ when 404
202
+ # Managed Source not found
203
+ raise InvalidDataError, err
204
+ else
205
+ raise APIError.new(err.http_code), 'Unexpected APIError code: ' + err.http_code.to_s + ' [' + err.message + ']'
206
+ end
207
+ end
208
+ end
209
+
210
+ #Delete this Managed Source
211
+ def delete()
212
+ raise InvalidDataError, 'Cannot delete a Managed source query that hasn\'t been prepared' unless @managed_source_id
213
+
214
+ begin
215
+ @user.callAPI('source/delete', { 'id' => @managed_source_id })
216
+ rescue APIError => err
217
+ case err.http_code
218
+ when 400
219
+ # Missing or invalid parameters
220
+ raise InvalidDataError, err
221
+ when 404
222
+ # Managed Source not found
223
+ raise InvalidDataError, err
224
+ else
225
+ raise APIError.new(err.http_code), 'Unexpected APIError code: ' + err.http_code.to_s + ' [' + err.message + ']'
226
+ end
227
+ end
228
+ end
229
+
230
+ end
231
+ end
data/lib/DataSift/user.rb CHANGED
@@ -1,267 +1,300 @@
1
1
  #This is the official DataSift client library for Ruby.
2
2
  module DataSift
3
- #The User class represents a user of the API. Applications should start their
4
- #API interactions by creating an instance of this class. Once initialised it
5
- #provides factory methods for all of the functionality in the API.
6
- class User
7
- #The user agent to pass through with all HTTP requests.
8
- USER_AGENT = 'DataSiftRuby/' + File.open(File.dirname(File.dirname(File.dirname(__FILE__))) + '/VERSION').first.strip!;
9
- #The base URL for API requests.
10
- API_BASE_URL = 'api.datasift.com/';
11
- #The base URL for streams.
12
- STREAM_BASE_URL = 'stream.datasift.com/';
3
+ #The User class represents a user of the API. Applications should start their
4
+ #API interactions by creating an instance of this class. Once initialised it
5
+ #provides factory methods for all of the functionality in the API.
6
+ class User
7
+ #The user agent to pass through with all HTTP requests.
8
+ USER_AGENT = 'DataSiftRuby/' + File.open(File.dirname(File.dirname(File.dirname(__FILE__))) + '/VERSION').first.strip!;
9
+ #The base URL for API requests.
10
+ API_BASE_URL = 'api.datasift.com/';
11
+ #The base URL for streams.
12
+ STREAM_BASE_URL = 'stream.datasift.com/';
13
13
 
14
- #The User's DataSift username.
15
- attr_reader :username
16
- #The User's DataSift API key.
17
- attr_reader :api_key
18
- #The User's total number of available hourly API credits. This is not
19
- #populated until an API request is made.
20
- attr_reader :rate_limit
21
- #The User's API credits remaining. This is not populated until an API
22
- #request is made.
23
- attr_reader :rate_limit_remaining
24
- #The APIClient class to use when making API requests.
25
- attr_reader :api_client
26
- #True if streaming connections should use SSL.
27
- attr_reader :use_ssl
14
+ #The User's DataSift username.
15
+ attr_reader :username
16
+ #The User's DataSift API key.
17
+ attr_reader :api_key
18
+ #The User's total number of available hourly API credits. This is not
19
+ #populated until an API request is made.
20
+ attr_reader :rate_limit
21
+ #The User's API credits remaining. This is not populated until an API
22
+ #request is made.
23
+ attr_reader :rate_limit_remaining
24
+ #The APIClient class to use when making API requests.
25
+ attr_reader :api_client
26
+ #True if streaming connections should use SSL.
27
+ attr_reader :use_ssl
28
28
 
29
- #Constructor. A username and API key are required when constructing an
30
- #instance of this class.
31
- #=== Parameters
32
- #* +username+ - The User's DataSift username
33
- #* +api_key+ - The User's DataSift API key
34
- def initialize(username, api_key, use_ssl = true)
35
- username.strip!
36
- api_key.strip!
29
+ #Constructor. A username and API key are required when constructing an
30
+ #instance of this class.
31
+ #=== Parameters
32
+ #* +username+ - The User's DataSift username
33
+ #* +api_key+ - The User's DataSift API key
34
+ def initialize(username, api_key, use_ssl = true)
35
+ username.strip!
36
+ api_key.strip!
37
37
 
38
- raise EInvalidData, 'Please supply valid credentials when creating a User object.' unless username.size > 0 and api_key.size > 0
38
+ raise EInvalidData, 'Please supply valid credentials when creating a User object.' unless username.size > 0 and api_key.size > 0
39
39
 
40
- @username = username
41
- @api_key = api_key
42
- @rate_limit = -1;
43
- @rate_limit_remaining = -1
44
- @use_ssl = use_ssl
45
- end
40
+ @username = username
41
+ @api_key = api_key
42
+ @rate_limit = -1;
43
+ @rate_limit_remaining = -1
44
+ @use_ssl = use_ssl
45
+ end
46
46
 
47
- #Creates and returns a definition object.
48
- #=== Parameters
49
- #* +csdl+ - Optional CSDL string with which to prime the object.
50
- #=== Returns
51
- #A Definition object.
52
- def createDefinition(csdl = '')
53
- DataSift::Definition.new(self, csdl, false)
54
- end
47
+ #Creates and returns a definition object.
48
+ #=== Parameters
49
+ #* +csdl+ - Optional CSDL string with which to prime the object.
50
+ #=== Returns
51
+ #A Definition object.
52
+ def createDefinition(csdl = '')
53
+ DataSift::Definition.new(self, csdl, false)
54
+ end
55
55
 
56
- #Create a Historics query based on this Definition.
57
- #=== Parameters
58
- #* +hash+ - The stream hash for a new Historics query.
59
- #* +start_date+ - The start date for a new Historics query.
60
- #* +end_date+ - The end date for a new Historics query.
61
- #* +sources+ - An array of sources for a new Historics query.
62
- #* +name+ - The name for a new Historics query.
63
- #* +sample+ - The sample rate for the new Historics query.
64
- #=== Returns
65
- #A Historic object.
66
- def createHistoric(hash, start_date, end_date, sources, sample, name)
67
- return Historic.new(self, hash, start_date, end_date, sources, sample, name)
68
- end
56
+ #Create a Historics query based on this Definition.
57
+ #=== Parameters
58
+ #* +hash+ - The stream hash for a new Historics query.
59
+ #* +start_date+ - The start date for a new Historics query.
60
+ #* +end_date+ - The end date for a new Historics query.
61
+ #* +sources+ - An array of sources for a new Historics query.
62
+ #* +name+ - The name for a new Historics query.
63
+ #* +sample+ - The sample rate for the new Historics query.
64
+ #=== Returns
65
+ #A Historic object.
66
+ def createHistoric(hash, start_date, end_date, sources, sample, name)
67
+ return Historic.new(self, hash, start_date, end_date, sources, sample, name)
68
+ end
69
69
 
70
- #Get a Historics query from the API.
71
- #=== Parameters
72
- #* +playback_id+ - The playback ID of the Historics query to retrieve.
73
- #=== Returns
74
- #A Historic object.
75
- def getHistoric(playback_id)
76
- return Historic.new(self, playback_id)
77
- end
70
+ #Get a Historics query from the API.
71
+ #=== Parameters
72
+ #* +playback_id+ - The playback ID of the Historics query to retrieve.
73
+ #=== Returns
74
+ #A Historic object.
75
+ def getHistoric(playback_id)
76
+ return Historic.new(self, playback_id)
77
+ end
78
78
 
79
- # Get a list of Historics queries in your account.
80
- #=== Parameters
81
- #* +page+ - The page number to get.
82
- #* +per_page+ - The number of items per page.
83
- #=== Returns
84
- #A Hash containing...
85
- #* +count+ - The total number of Historics queries in your account.
86
- #* +historics+ - An array of Hashes where each Hash is a Historics query.
87
- def listHistorics(page = 1, per_page = 20)
88
- return Historic::list(self, page, per_page)
89
- end
79
+ # Get a list of Historics queries in your account.
80
+ #=== Parameters
81
+ #* +page+ - The page number to get.
82
+ #* +per_page+ - The number of items per page.
83
+ #=== Returns
84
+ #A Hash containing...
85
+ #* +count+ - The total number of Historics queries in your account.
86
+ #* +historics+ - An array of Hashes where each Hash is a Historics query.
87
+ def listHistorics(page = 1, per_page = 20)
88
+ return Historic::list(self, page, per_page)
89
+ end
90
90
 
91
- #Create a new PushDefinition object for this user.
92
- #=== Returns
93
- #A PushDefinition object.
94
- def createPushDefinition()
95
- return PushDefinition.new(self)
96
- end
97
91
 
98
- #Get an existing PushSubscription from the API.
99
- #=== Parameters
100
- #* +subscription_id+ - The ID of the subscription to fetch.
101
- #=== Returns
102
- #A PushSubscription object.
103
- def getPushSubscription(subscription_id)
104
- return PushSubscription.get(self, subscription_id)
105
- end
92
+ #Create a Managed Source query based on this Definition.
93
+ #=== Options
94
+ #* +hash+ - Contains parameters to set up your Managed Source
95
+ #=== Returns
96
+ #A Managed Source object.
97
+ def createManagedSource(hash = {})
98
+ managed_source = ManagedSource.new(self, hash)
99
+ managed_source.create
100
+ return managed_source
101
+ end
106
102
 
107
- #Get the log entries for all push subscription or the given subscription.
108
- #=== Parameters
109
- #* +subscription_id+ - Optional subscription ID.
110
- #=== Returns
111
- #A Hash containing...
112
- #* +count+ - The total number of matching log entries.
113
- #* +log_entries+ - An array of Hashes where each Hash is a log entry.
114
- def getPushSubscriptionLog(subscription_id = false)
115
- if subscription_id
116
- return getPushSubscription(subscription_id).getLog()
117
- else
118
- return PushSubscription.getLogs(self)
119
- end
120
- end
103
+ #Get a Manged Source query from the API.
104
+ #=== Parameters
105
+ #* +managed_source_id+ - The ID of the Managed Source to retrieve.
106
+ #=== Returns
107
+ #A Managed Source object.
108
+ def getManagedSource(managed_source_id)
109
+ return ManagedSource.get(self, managed_source_id)
110
+ end
121
111
 
122
- #Get a page of Push subscriptions in the given user's account, where each
123
- #page contains up to per_page items. Results will be ordered according to
124
- #the supplied ordering parameters.
125
- #=== Parameters
126
- #* +page+ - The page number to get.
127
- #* +per_page+ - The number of items per page.
128
- #* +order_by+ - The field by which to order the results.
129
- #* +order_dir+ - Ascending or descending.
130
- #* +include_finished+ - True to include subscriptions against finished Historics queries.
131
- #=== Returns
132
- #A Hash containing...
133
- #* +count+ - The total number of matching Push subscriptions in your account.
134
- #* +subscriptions+ - An array of Hashes where each Hash is a Push subscription.
135
- def listPushSubscriptions(page = 1, per_page = 20, order_by = PushSubscription::ORDERBY_CREATED_AT, order_dir = PushSubscription::ORDERDIR_ASC, include_finished = false)
136
- return PushSubscription.list(self, page, per_page, order_by, order_dir, include_finished)
137
- end
112
+ # Get a list of ManagedSources in your account.
113
+ #=== Parameters
114
+ #* +page+ - The page number to get.
115
+ #* +per_page+ - The number of items per page.
116
+ #=== Returns
117
+ #A Hash containing...
118
+ #* +count+ - The total number of Managed Sources in your account.
119
+ #* +managed_sources+ - An array of Hashes where each Hash is a managed source.
120
+ def listManagedSources(page = 1, per_page = 20)
121
+ return ManagedSource::list(self, page, per_page)
122
+ end
138
123
 
139
- #Get a page of Push subscriptions in the given user's account, where each
140
- #page contains up to per_page items. Results will be ordered according to
141
- #the supplied ordering parameters.
142
- #=== Parameters
143
- #* +hash+ - The stream hash.
144
- #* +page+ - The page number to get.
145
- #* +per_page+ - The number of items per page.
146
- #* +order_by+ - The field by which to order the results.
147
- #* +order_dir+ - Ascending or descending.
148
- #* +include_finished+ - True to include subscriptions against finished Historics queries.
149
- #=== Returns
150
- #A Hash containing...
151
- #* +count+ - The total number of matching Push subscriptions in your account.
152
- #* +subscriptions+ - An array of Hashes where each Hash is a Push subscription.
153
- def listPushSubscriptionsToStreamHash(hash, page = 1, per_page = 20, order_by = PushSubscription::ORDERBY_CREATED_AT, order_dir = PushSubscription::ORDERDIR_ASC, include_finished = false)
154
- return PushSubscription.listByStreamHash(self, hash, page, per_page, order_by, order_dir)
155
- end
124
+ #Create a new PushDefinition object for this user.
125
+ #=== Returns
126
+ #A PushDefinition object.
127
+ def createPushDefinition()
128
+ return PushDefinition.new(self)
129
+ end
156
130
 
157
- #Get a page of Push subscriptions in the given user's account, where each
158
- #page contains up to per_page items. Results will be ordered according to
159
- #the supplied ordering parameters.
160
- #=== Parameters
161
- #* +hash+ - The stream hash.
162
- #* +page+ - The page number to get.
163
- #* +per_page+ - The number of items per page.
164
- #* +order_by+ - The field by which to order the results.
165
- #* +order_dir+ - Ascending or descending.
166
- #* +include_finished+ - True to include subscriptions against finished Historics queries.
167
- #=== Returns
168
- #A Hash containing...
169
- #* +count+ - The total number of matching Push subscriptions in your account.
170
- #* +subscriptions+ - An array of Hashes where each Hash is a Push subscription.
171
- def listPushSubscriptionsToPlaybackId(playback_id, page = 1, per_page = 20, order_by = PushSubscription::ORDERBY_CREATED_AT, order_dir = PushSubscription::ORDERDIR_ASC, include_finished = false)
172
- return PushSubscription.listByPlaybackId(self, playback_id, page, per_page, order_by, order_dir)
173
- end
131
+ #Get an existing PushSubscription from the API.
132
+ #=== Parameters
133
+ #* +subscription_id+ - The ID of the subscription to fetch.
134
+ #=== Returns
135
+ #A PushSubscription object.
136
+ def getPushSubscription(subscription_id)
137
+ return PushSubscription.get(self, subscription_id)
138
+ end
174
139
 
175
- #Returns a StreamConsumer-derived object for the given hash, for the
176
- #given type.
177
- #=== Parameters
178
- #* +type+ - The consumer type for which to construct a consumer.
179
- #* +hash+ - The hash to be consumed.
180
- #=== Returns
181
- #A StreamConsumer-derived object.
182
- def getConsumer(type = nil, hash = nil, on_interaction = nil, on_stopped = nil)
183
- StreamConsumer.factory(self, type, Definition.new(self, nil, hash))
184
- end
140
+ #Get the log entries for all push subscription or the given subscription.
141
+ #=== Parameters
142
+ #* +subscription_id+ - Optional subscription ID.
143
+ #=== Returns
144
+ #A Hash containing...
145
+ #* +count+ - The total number of matching log entries.
146
+ #* +log_entries+ - An array of Hashes where each Hash is a log entry.
147
+ def getPushSubscriptionLog(subscription_id = false)
148
+ if subscription_id
149
+ return getPushSubscription(subscription_id).getLog()
150
+ else
151
+ return PushSubscription.getLogs(self)
152
+ end
153
+ end
185
154
 
186
- #Returns the account balance information for this user.
187
- #=== Returns
188
- #A Hash containing the balance information.
189
- def getBalance
190
- return callAPI('balance')['balance']
191
- end
155
+ #Get a page of Push subscriptions in the given user's account, where each
156
+ #page contains up to per_page items. Results will be ordered according to
157
+ #the supplied ordering parameters.
158
+ #=== Parameters
159
+ #* +page+ - The page number to get.
160
+ #* +per_page+ - The number of items per page.
161
+ #* +order_by+ - The field by which to order the results.
162
+ #* +order_dir+ - Ascending or descending.
163
+ #* +include_finished+ - True to include subscriptions against finished Historics queries.
164
+ #=== Returns
165
+ #A Hash containing...
166
+ #* +count+ - The total number of matching Push subscriptions in your account.
167
+ #* +subscriptions+ - An array of Hashes where each Hash is a Push subscription.
168
+ def listPushSubscriptions(page = 1, per_page = 20, order_by = PushSubscription::ORDERBY_CREATED_AT, order_dir = PushSubscription::ORDERDIR_ASC, include_finished = false)
169
+ return PushSubscription.list(self, page, per_page, order_by, order_dir, include_finished)
170
+ end
192
171
 
193
- #Returns the usage data for this user. If a hash is provided then a more
194
- #detailed breakdown using interaction types is retrieved and returned.
195
- #=== Parameters
196
- #* +period+ - An optional period for which to fetch data ('hour' or 'day')
197
- #=== Returns
198
- #A Hash containing the usage information.
199
- def getUsage(period = 'hour')
200
- params = { 'period' => period }
172
+ #Get a page of Push subscriptions in the given user's account, where each
173
+ #page contains up to per_page items. Results will be ordered according to
174
+ #the supplied ordering parameters.
175
+ #=== Parameters
176
+ #* +hash+ - The stream hash.
177
+ #* +page+ - The page number to get.
178
+ #* +per_page+ - The number of items per page.
179
+ #* +order_by+ - The field by which to order the results.
180
+ #* +order_dir+ - Ascending or descending.
181
+ #* +include_finished+ - True to include subscriptions against finished Historics queries.
182
+ #=== Returns
183
+ #A Hash containing...
184
+ #* +count+ - The total number of matching Push subscriptions in your account.
185
+ #* +subscriptions+ - An array of Hashes where each Hash is a Push subscription.
186
+ def listPushSubscriptionsToStreamHash(hash, page = 1, per_page = 20, order_by = PushSubscription::ORDERBY_CREATED_AT, order_dir = PushSubscription::ORDERDIR_ASC, include_finished = false)
187
+ return PushSubscription.listByStreamHash(self, hash, page, per_page, order_by, order_dir)
188
+ end
201
189
 
202
- return callAPI('usage', params)
203
- end
190
+ #Get a page of Push subscriptions in the given user's account, where each
191
+ #page contains up to per_page items. Results will be ordered according to
192
+ #the supplied ordering parameters.
193
+ #=== Parameters
194
+ #* +hash+ - The stream hash.
195
+ #* +page+ - The page number to get.
196
+ #* +per_page+ - The number of items per page.
197
+ #* +order_by+ - The field by which to order the results.
198
+ #* +order_dir+ - Ascending or descending.
199
+ #* +include_finished+ - True to include subscriptions against finished Historics queries.
200
+ #=== Returns
201
+ #A Hash containing...
202
+ #* +count+ - The total number of matching Push subscriptions in your account.
203
+ #* +subscriptions+ - An array of Hashes where each Hash is a Push subscription.
204
+ def listPushSubscriptionsToPlaybackId(playback_id, page = 1, per_page = 20, order_by = PushSubscription::ORDERBY_CREATED_AT, order_dir = PushSubscription::ORDERDIR_ASC, include_finished = false)
205
+ return PushSubscription.listByPlaybackId(self, playback_id, page, per_page, order_by, order_dir)
206
+ end
204
207
 
205
- #Returns the user agent this library should use for all API calls.
206
- #=== Returns
207
- #The user agent string.
208
- def getUserAgent()
209
- return USER_AGENT
210
- end
208
+ #Returns a StreamConsumer-derived object for the given hash, for the
209
+ #given type.
210
+ #=== Parameters
211
+ #* +type+ - The consumer type for which to construct a consumer.
212
+ #* +hash+ - The hash to be consumed.
213
+ #=== Returns
214
+ #A StreamConsumer-derived object.
215
+ def getConsumer(type = nil, hash = nil, on_interaction = nil, on_stopped = nil)
216
+ StreamConsumer.factory(self, type, Definition.new(self, nil, hash))
217
+ end
211
218
 
212
- #Sets the ApiClient object to use to access the API
213
- #=== Parameters
214
- #* +client+ - The API client object to be used.
215
- def setApiClient(client)
216
- @api_client = client
217
- end
219
+ #Returns the account balance information for this user.
220
+ #=== Returns
221
+ #A Hash containing the balance information.
222
+ def getBalance
223
+ return callAPI('balance')['balance']
224
+ end
218
225
 
219
- #Sets whether to use SSL for API and stream communication.
220
- #=== Parameters
221
- #* +use_ssl+ - Pass true to use SSL.
222
- def enableSSL(use_ssl = true)
223
- @use_ssl = use_ssl
224
- end
226
+ #Returns the usage data for this user. If a hash is provided then a more
227
+ #detailed breakdown using interaction types is retrieved and returned.
228
+ #=== Parameters
229
+ #* +period+ - An optional period for which to fetch data ('hour' or 'day')
230
+ #=== Returns
231
+ #A Hash containing the usage information.
232
+ def getUsage(period = 'hour')
233
+ params = { 'period' => period }
225
234
 
226
- #Make a call to a DataSift API endpoint.
227
- #=== Parameters
228
- #* +endpoint+ - The endpoint of the API call.
229
- #* +params+ - A Hash of parameters to be passed along with the request.
230
- #=== Returns
231
- #A Hash containing the response data.
232
- def callAPI(endpoint, params = {})
233
- if !@api_client
234
- @api_client = ApiClient.new()
235
- end
235
+ return callAPI('usage', params)
236
+ end
236
237
 
237
- res = @api_client.call(self, endpoint, params, getUserAgent())
238
+ #Returns the user agent this library should use for all API calls.
239
+ #=== Returns
240
+ #The user agent string.
241
+ def getUserAgent()
242
+ return USER_AGENT
243
+ end
238
244
 
239
- # Set up the return value
240
- retval = res['data']
245
+ #Sets the ApiClient object to use to access the API
246
+ #=== Parameters
247
+ #* +client+ - The API client object to be used.
248
+ def setApiClient(client)
249
+ @api_client = client
250
+ end
241
251
 
242
- # Update the rate limits from the headers
243
- @rate_limit = res['rate_limit']
244
- @rate_limit_remaining = res['rate_limit_remaining']
252
+ #Sets whether to use SSL for API and stream communication.
253
+ #=== Parameters
254
+ #* +use_ssl+ - Pass true to use SSL.
255
+ def enableSSL(use_ssl = true)
256
+ @use_ssl = use_ssl
257
+ end
245
258
 
246
- case res['response_code']
247
- when 200
248
- when 201
249
- when 202
250
- when 204
251
- # Do nothing
252
- when 401
253
- # Authentication failure
254
- raise AccessDeniedError, retval.has_key?('error') ? retval['error'] : 'Authentication failed'
255
- when 403
256
- # Check the rate limit
257
- raise RateLimitExceededError, retval['comment'] if @rate_limit_remaining == 0
258
- # Rate limit is ok, raise a generic exception
259
- raise APIError.new(res['response_code']), retval.has_key?('error') ? retval['error'] : 'Unknown error'
260
- else
261
- raise APIError.new(res['response_code']), retval.has_key?('error') ? retval['error'] : 'Unknown error'
262
- end
259
+ #Make a call to a DataSift API endpoint.
260
+ #=== Parameters
261
+ #* +endpoint+ - The endpoint of the API call.
262
+ #* +params+ - A Hash of parameters to be passed along with the request.
263
+ #=== Returns
264
+ #A Hash containing the response data.
265
+ def callAPI(endpoint, params = {})
266
+ if !@api_client
267
+ @api_client = ApiClient.new()
268
+ end
263
269
 
264
- return retval
265
- end
266
- end
270
+ res = @api_client.call(self, endpoint, params, getUserAgent())
271
+
272
+ # Set up the return value
273
+ retval = res['data']
274
+
275
+ # Update the rate limits from the headers
276
+ @rate_limit = res['rate_limit']
277
+ @rate_limit_remaining = res['rate_limit_remaining']
278
+
279
+ case res['response_code']
280
+ when 200
281
+ when 201
282
+ when 202
283
+ when 204
284
+ # Do nothing
285
+ when 401
286
+ # Authentication failure
287
+ raise AccessDeniedError, retval.has_key?('error') ? retval['error'] : 'Authentication failed'
288
+ when 403
289
+ # Check the rate limit
290
+ raise RateLimitExceededError, retval['comment'] if @rate_limit_remaining == 0
291
+ # Rate limit is ok, raise a generic exception
292
+ raise APIError.new(res['response_code']), retval.has_key?('error') ? retval['error'] : 'Unknown error'
293
+ else
294
+ raise APIError.new(res['response_code']), retval.has_key?('error') ? retval['error'] : 'Unknown error'
295
+ end
296
+
297
+ return retval
298
+ end
299
+ end
267
300
  end
data/lib/datasift.rb CHANGED
@@ -12,3 +12,4 @@ require dir + '/DataSift/push_definition'
12
12
  require dir + '/DataSift/push_subscription'
13
13
  require dir + '/DataSift/stream_consumer'
14
14
  require dir + '/DataSift/stream_consumer_http'
15
+ require dir + '/DataSift/managed_source'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datasift
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.1.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - DataSift
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2013-03-18 00:00:00 Z
12
+ date: 2013-08-05 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -32,38 +32,48 @@ dependencies:
32
32
  type: :runtime
33
33
  version_requirements: *id002
34
34
  - !ruby/object:Gem::Dependency
35
- name: rdoc
35
+ name: json
36
36
  prerelease: false
37
37
  requirement: &id003 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 1.5.4
42
+ type: :runtime
43
+ version_requirements: *id003
44
+ - !ruby/object:Gem::Dependency
45
+ name: rdoc
46
+ prerelease: false
47
+ requirement: &id004 !ruby/object:Gem::Requirement
38
48
  requirements:
39
49
  - - ">"
40
50
  - !ruby/object:Gem::Version
41
51
  version: "0"
42
52
  type: :development
43
- version_requirements: *id003
53
+ version_requirements: *id004
44
54
  - !ruby/object:Gem::Dependency
45
55
  name: shoulda
46
56
  prerelease: false
47
- requirement: &id004 !ruby/object:Gem::Requirement
57
+ requirement: &id005 !ruby/object:Gem::Requirement
48
58
  requirements:
49
59
  - - ~>
50
60
  - !ruby/object:Gem::Version
51
61
  version: 2.11.3
52
62
  type: :development
53
- version_requirements: *id004
63
+ version_requirements: *id005
54
64
  - !ruby/object:Gem::Dependency
55
65
  name: rspec
56
66
  prerelease: false
57
- requirement: &id005 !ruby/object:Gem::Requirement
67
+ requirement: &id006 !ruby/object:Gem::Requirement
58
68
  requirements:
59
69
  - - ~>
60
70
  - !ruby/object:Gem::Version
61
71
  version: 2.6.0
62
72
  type: :development
63
- version_requirements: *id005
73
+ version_requirements: *id006
64
74
  description: The official Ruby library for accessing the DataSift API. See http://datasift.com/ for full details and to sign up for an account.
65
75
  email:
66
- - support@datasift.net
76
+ - support@datasift.com
67
77
  executables: []
68
78
 
69
79
  extensions: []
@@ -110,6 +120,7 @@ files:
110
120
  - lib/DataSift/definition.rb
111
121
  - lib/DataSift/exceptions.rb
112
122
  - lib/DataSift/historic.rb
123
+ - lib/DataSift/managed_source.rb
113
124
  - lib/DataSift/mockapiclient.rb
114
125
  - lib/DataSift/push_definition.rb
115
126
  - lib/DataSift/push_subscription.rb
@@ -147,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
158
  requirements: []
148
159
 
149
160
  rubyforge_project:
150
- rubygems_version: 2.0.3
161
+ rubygems_version: 2.0.5
151
162
  signing_key:
152
163
  specification_version: 4
153
164
  summary: DataSift is a simple wrapper for the DataSift API.