Skip to content

Commit

Permalink
Adds RateLimitException for 429 errors, passing the timestamp when th…
Browse files Browse the repository at this point in the history
…e counter resets to the error.

Bumps version to 0.0.4.
  • Loading branch information
derikolsson committed May 22, 2015
1 parent 68a5ed2 commit 0e676e2
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 40 deletions.
1 change: 0 additions & 1 deletion gem-ooyala-v2-api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ gem "json"

group :development do
gem "shoulda", ">= 0"
gem "rdoc"
gem "bundler"
gem "jeweler"
gem "simplecov", ">= 0"
Expand Down
88 changes: 88 additions & 0 deletions gem-ooyala-v2-api/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
GEM
remote: http://rubygems.org/
specs:
activesupport (4.2.1)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.8)
builder (3.2.2)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
docile (1.1.5)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
git (1.2.9.1)
github_api (0.12.3)
addressable (~> 2.3)
descendants_tracker (~> 0.0.4)
faraday (~> 0.8, < 0.10)
hashie (>= 3.3)
multi_json (>= 1.7.5, < 2.0)
nokogiri (~> 1.6.3)
oauth2
hashie (3.4.1)
highline (1.7.2)
i18n (0.7.0)
jeweler (2.0.1)
builder
bundler (>= 1.0)
git (>= 1.2.5)
github_api
highline (>= 1.6.15)
nokogiri (>= 1.5.10)
rake
rdoc
json (1.8.2)
jwt (1.5.0)
mime-types (1.25.1)
mini_portile (0.6.2)
minitest (5.6.1)
multi_json (1.11.0)
multi_xml (0.5.5)
multipart-post (2.0.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
oauth2 (1.0.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
rack (1.6.1)
rake (10.4.2)
rdoc (4.2.0)
rest-client (1.6.8)
mime-types (~> 1.16)
rdoc (>= 2.4.2)
rr (1.1.2)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
shoulda-context (1.2.1)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
simplecov (0.10.0)
docile (~> 1.1.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)

PLATFORMS
ruby

DEPENDENCIES
bundler
jeweler
json
rake
rdoc
rest-client (~> 1.6.6)
rr
shoulda
simplecov
8 changes: 2 additions & 6 deletions gem-ooyala-v2-api/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ Jeweler::Tasks.new do |gem|
gem.homepage = "https://github.com/ooyala/api-sdks"
gem.license = "MIT"
gem.summary = %Q{Ooyala's API SDK}
gem.description = %Q{Contains the necessary mehtods to communicate with the Ooyala's API.}
gem.description = %Q{Contains the necessary methods to communicate with the Ooyala API.}
gem.email = "[email protected]"
gem.authors = ["Ooyala"]
# dependencies defined in Gemfile
# dependencies defined in Gemfile
gem.add_dependency('json')
gem.add_dependency('rest-client', "~> 1.6.6")
gem.authors = ["Ooyala","DerikOlsson"]
end
Jeweler::RubygemsDotOrgTasks.new

Expand Down
2 changes: 1 addition & 1 deletion gem-ooyala-v2-api/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.3
0.0.4
11 changes: 10 additions & 1 deletion gem-ooyala-v2-api/lib/ooyala-v2-api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,13 @@ def send_request(http_method, request_path, query_params = {},
return [] if response.body.empty?
JSON.parse(response.body)
rescue RestClient::Exception => ex
raise Ooyala::RequestErrorException.new(ex.inspect)
if ex.http_code == 429
scan = ex.inspect.scan(/(\d+)\ssecond/)
delay = scan[0][0].to_i
raise Ooyala::RateLimitException.new((Time.now + delay))
else
raise Ooyala::RequestErrorException.new(ex.inspect)
end
end

# Builds the URL for a request. Adds the query parameters, the signature
Expand Down Expand Up @@ -302,4 +308,7 @@ class RequestErrorException < StandardError

class MethodNotSupportedException < StandardError
end

class RateLimitException < StandardError
end
end
59 changes: 28 additions & 31 deletions gem-ooyala-v2-api/ooyala-v2-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,69 @@
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
# stub: ooyala-v2-api 0.0.4 ruby lib

Gem::Specification.new do |s|
s.name = "ooyala-v2-api"
s.version = "0.0.3"
s.version = "0.0.4"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jose Gasca"]
s.date = "2013-05-21"
s.description = "This gem allows the interaction with the Ooyala's API v2."
s.require_paths = ["lib"]
s.authors = ["Ooyala", "DerikOlsson"]
s.date = "2015-05-22"
s.description = "Contains the necessary methods to communicate with the Ooyala API."
s.email = "[email protected]"
s.extra_rdoc_files = [
"LICENSE.txt",
"README.rdoc"
]
s.files = [
".document",
"Gemfile",
"Gemfile.lock",
"LICENSE.txt",
"README.rdoc",
"Rakefile",
"VERSION",
"lib/ooyala-v2-api.rb",
"ooyala-v2-api-0.0.3.gem",
"ooyala-v2-api.gemspec",
"test/helper.rb",
"test/test_ooyala-v2-api.rb"
]
s.homepage = "http://api.ooyala.com/docs/v2/api_libraries"
s.licenses = ["See license.txt"]
s.require_paths = ["lib"]
s.rubygems_version = "1.8.10"
s.summary = "Ooyala's API v2 Ruby SDK"
s.homepage = "https://github.com/ooyala/api-sdks"
s.licenses = ["MIT"]
s.rubygems_version = "2.4.5"
s.summary = "Ooyala's API SDK"

if s.respond_to? :specification_version then
s.specification_version = 3
s.specification_version = 4

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rdoc>, [">= 0"])
s.add_runtime_dependency(%q<rake>, [">= 0"])
s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.6"])
s.add_runtime_dependency(%q<json>, [">= 0"])
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
s.add_development_dependency(%q<tomdoc>, [">= 0"])
s.add_runtime_dependency(%q<json>, [">= 0"])
s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.6"])
s.add_development_dependency(%q<shoulda>, [">= 0"])
s.add_development_dependency(%q<bundler>, [">= 0"])
s.add_development_dependency(%q<jeweler>, [">= 0"])
s.add_development_dependency(%q<simplecov>, [">= 0"])
s.add_development_dependency(%q<rr>, [">= 0"])
else
s.add_dependency(%q<rdoc>, [">= 0"])
s.add_dependency(%q<rake>, [">= 0"])
s.add_dependency(%q<rest-client>, ["~> 1.6.6"])
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
s.add_dependency(%q<tomdoc>, [">= 0"])
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<rest-client>, ["~> 1.6.6"])
s.add_dependency(%q<shoulda>, [">= 0"])
s.add_dependency(%q<bundler>, [">= 0"])
s.add_dependency(%q<jeweler>, [">= 0"])
s.add_dependency(%q<simplecov>, [">= 0"])
s.add_dependency(%q<rr>, [">= 0"])
end
else
s.add_dependency(%q<rdoc>, [">= 0"])
s.add_dependency(%q<rake>, [">= 0"])
s.add_dependency(%q<rest-client>, ["~> 1.6.6"])
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
s.add_dependency(%q<tomdoc>, [">= 0"])
s.add_dependency(%q<json>, [">= 0"])
s.add_dependency(%q<rest-client>, ["~> 1.6.6"])
s.add_dependency(%q<shoulda>, [">= 0"])
s.add_dependency(%q<bundler>, [">= 0"])
s.add_dependency(%q<jeweler>, [">= 0"])
s.add_dependency(%q<simplecov>, [">= 0"])
s.add_dependency(%q<rr>, [">= 0"])
end
end

0 comments on commit 0e676e2

Please sign in to comment.