Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #91 from datasift/api_v1_6
Browse files Browse the repository at this point in the history
Updated to API v1.6
  • Loading branch information
dugjason committed Jan 17, 2018
2 parents 054e91b + 43e3f43 commit d724e4f
Show file tree
Hide file tree
Showing 174 changed files with 215 additions and 291 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Expand Up @@ -3,16 +3,20 @@ sudo: false
cache: bundler
bundler_args: --without development --retry=3 --jobs=3

before_install:
# Workaround for https://github.com/travis-ci/travis-ci/issues/8969
- gem update --system

rvm:
- 2.1
- 2.2
- 2.3
- 2.4
- ruby-head
- 2.5

matrix:
allow_failures:
- 1.9
- 2.0
- 2.1
- ruby-head
fast_finish: true
10 changes: 4 additions & 6 deletions CHANGELOG.md
@@ -1,11 +1,9 @@
CHANGELOG
================================
## v.4.0 (Under development)
### Planned Features
* Better thought out API design in a more traditional Gem style
* More of an SDK style library; for example, you should perform actions (start/stop/analyze) on a PYLON recording object
* Designed to make the most of DataSift's latest API version and features
* Designed for Ruby 2.3+. Use features like keyword parameters across the board
## v.3.10.0 (2018-01-15)
### Changed
* Uses API v1.6 by default
* Change to `account.usage()` required by API; start/end times must be included

## v.3.9.0 (2017-08-16)
### Added
Expand Down
13 changes: 12 additions & 1 deletion README.md
Expand Up @@ -85,9 +85,11 @@ This version of the client library has been tested, and is known to work against
### Language Versions
* Ruby 1.9.3 (May work, but no longer officially supported)
* Ruby 2.0 (May work, but no longer officially supported)
* Ruby 2.1
* Ruby 2.1 (May work, but no longer officially supported)
* Ruby 2.2
* Ruby 2.3
* Ruby 2.4
* Ruby 2.5

### Operating Systems
* Linux
Expand All @@ -103,6 +105,15 @@ Contributions are always welcome and appreciated
2. Create a feature branch (we use [Gitflow](https://datasift.github.io/gitflow/IntroducingGitFlow.html) for branching)
3. Commit your changes with tests. Please try not to break backwards-compatibility :)

Testing
-------
When contributing new code, it should be accompanied with appropriate tests.
When adding new tests, or testing a new API version, you should follow these steps:
1. Add your credentials and appropriate API version to the `examples/auth.rb` file (these credentials will not be stored anywhere. Please remember to remove them before committing code!)
2. Run `bundle install; rake build; rake install` to ensure we are using the latest versions of your changes
3. Run `rake test` to run the full test suite, or you can run `ruby test/datasift/<test_file>` to run just a specific test.
4. When you have successfully tested your changes, and stored the API response from any new API calls using VCR (see the `test/fixtures/cassettes` directory), run `rake test` again to run the full test suite. If that passes, you should be good to commit and push your changes.

License
-------
This code is released under the BSD license. Please see the [LICENSE](LICENSE) file for details.
13 changes: 9 additions & 4 deletions examples/account_eg.rb
@@ -1,4 +1,6 @@
require './auth'
require 'date'

class AccountEg < DataSiftExample
def initialize
super
Expand All @@ -8,11 +10,14 @@ def initialize

def run
begin
puts "Get account usage for the default period"
puts @datasift.account.usage[:data].to_json
start_time = DateTime.strptime('01/12/2017', '%d/%m/%Y').to_time.to_i
end_time = DateTime.strptime('01/01/2018', '%d/%m/%Y').to_time.to_i

puts "Get account usage for a specific time period using the default date granulatiry"
puts @datasift.account.usage(start_time, end_time)[:data].to_json

puts "\nGet account usage for the past month"
puts @datasift.account.usage('monthly')[:data].to_json
puts "\nGet account usage for a specific month"
puts @datasift.account.usage(start_time, end_time, 'monthly')[:data].to_json

rescue DataSiftError => dse
puts dse.message
Expand Down
2 changes: 1 addition & 1 deletion examples/auth.rb
Expand Up @@ -6,7 +6,7 @@ def initialize
@config = {
username: 'DATASIFT_USERNAME',
api_key: 'DATASIFT_API_KEY',
api_version: 'v1.5'
api_version: 'v1.6'
}
@params = {
output_type: 's3',
Expand Down
6 changes: 2 additions & 4 deletions lib/account.rb
Expand Up @@ -10,11 +10,9 @@ class Account < DataSift::ApiResource
# @param end_time [Integer] (Optional) Unix timestamp of the end of the period
# you are querying
# @return [Object] API reponse object
def usage(period = '', start_time = nil, end_time = nil)
params = {}
def usage(start_time, end_time, period = '')
params = { start: start_time, end: end_time }
params.merge!(period: period) unless period.empty?
params.merge!(start: start_time) unless start_time.nil?
params.merge!(end: end_time) unless end_time.nil?

DataSift.request(:GET, 'account/usage', @config, params)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/api/api_resource.rb
Expand Up @@ -14,7 +14,7 @@ def initialize(config)
config[:api_host] = 'api.datasift.com' unless config.has_key?(:api_host)
config[:stream_host] = 'websocket.datasift.com' unless config.has_key?(:stream_host)
config[:ingestion_host] = 'in.datasift.com' unless config.has_key?(:ingestion_host)
config[:api_version] = 'v1.5' unless config.has_key?(:api_version)
config[:api_version] = 'v1.6' unless config.has_key?(:api_version)
config[:enable_ssl] = true unless config.has_key?(:enable_ssl)

ssl_default = TLSv1_2
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
@@ -1,3 +1,3 @@
module DataSift
VERSION = '3.9.0'.freeze
VERSION = '3.10.0'.freeze
end
18 changes: 15 additions & 3 deletions test/datasift/account/account_api_test.rb
Expand Up @@ -12,18 +12,30 @@
it 'can get account usage using valid params' do
VCR.use_cassette("#{@datasift.config[:api_version]}" + '/account/usage/valid_params') do
response = @datasift.account.usage(
'daily',
1490054400,
1490572800
1490572800,
'daily'
)
assert_equal STATUS.valid, response[:http][:status]
end
end

it 'raises argument error when using invalid params' do
VCR.use_cassette("#{@datasift.config[:api_version]}" + '/account/usage/invalid') do
assert_raises ArgumentError do
@datasift.account.usage()
end
end
end

it 'handles 400 when using invalid params' do
VCR.use_cassette("#{@datasift.config[:api_version]}" + '/account/usage/invalid') do
assert_raises BadRequestError do
@datasift.account.usage('invalid_period')
@datasift.account.usage(
1490054400,
1490572800,
'invalid_period'
)
end
end
end
Expand Down

0 comments on commit d724e4f

Please sign in to comment.