redd 0.7.7 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3926dca6aabc517fcbc74ca6a5dbb9455b4ba7e2
4
- data.tar.gz: eea4c39a875a1020dad663edcf77bf96fcac8d1a
3
+ metadata.gz: 1ed185709399c5e0bf0984f8323b710b977b8b24
4
+ data.tar.gz: 51d437dfc4f6d2477e33db31e5ef3c340f36e34c
5
5
  SHA512:
6
- metadata.gz: f5f649f74ca1fcef2ec2d5bd885cd993a0c85c89b9423cc9eeb77a80cdea56a01735c2e59d4a6e5d94d718ef1ee52240628f5ee749e47e4df750ab32107fef15
7
- data.tar.gz: bd87e00808c774e53f60dbba84c6185e875e5c6643d9abb6cf43bbb2854365faa097ff30edab91a0d4a3c6bf3ba15c6cff2f18de33a6bbfce85f84fbcd3d2d87
6
+ metadata.gz: 772c63c331ccfdb175ab743f36a994147d949f2cbc16179eede313b87985f2a0ed450498f6a170d6e69bda234cc610a23c4dd1ffc0b05aaa3908fc1b97e24bce
7
+ data.tar.gz: 86330606ecb14b4ec43d834af0f48bc47495761a9d3c5ae30e5411422ec7c10d0ddf66cd1dc8c8f404370d7e9dce5f12789399d53fc31a469fc71e95768a336e
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  <a href="https://rubygems.org/gems/redd"><img src="http://img.shields.io/gem/v/redd.svg?style=flat-square" alt="Gem Version"></a>
4
4
  <a href="https://travis-ci.org/avidw/redd"><img src="http://img.shields.io/travis/avidw/redd.svg?style=flat-square" alt="Build Status"></a>
5
5
  <a href="https://rubygems.org/gems/redd"><img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT License"></a>
6
+ <a href="https://gitter.im/avidw/redd?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://img.shields.io/badge/GITTER-JOIN%20CHAT%20%E2%86%92-1dce73.svg?style=flat-square" alt="Chat on Gitter"></a>
6
7
  </p>
7
8
 
8
9
  **redd** is an API wrapper for [reddit](http://www.reddit.com/dev/api) written in ruby that focuses on being consistent and extensible. **Check out the latest documentation on [RubyDoc](http://www.rubydoc.info/github/avidw/redd/master/frames/Redd.it).**
@@ -88,6 +89,7 @@ hot.each { |link| puts "#{link.title} by /u/#{link.author}" }
88
89
  # Streaming
89
90
  def stream_all!
90
91
  r.stream :get_comments, "all" do |comment|
92
+ reddit.refresh_access! if reddit.access.expired? # for :web
91
93
  comment.reply("World!") if comment.body == "Hello?"
92
94
  end
93
95
  end
@@ -44,7 +44,7 @@ module Redd
44
44
 
45
45
  # @return [Boolean] Whether the access has expired.
46
46
  def expired?
47
- Time.now > @expires_at
47
+ Time.now > (@expires_at + 60)
48
48
  end
49
49
 
50
50
  # Refresh the object with the new response body.
@@ -81,7 +81,7 @@ module Redd
81
81
  # @param params [Hash] A list of params to send with the request.
82
82
  # @option params [String] :after Return results after the given
83
83
  # fullname.
84
- # @option params [String :before Return results before the given
84
+ # @option params [String] :before Return results before the given
85
85
  # fullname.
86
86
  # @option params [Integer] :count The number of items already seen in
87
87
  # the listing.
@@ -33,6 +33,9 @@ module Redd
33
33
 
34
34
  @access = Access.new(response.body)
35
35
  end
36
+
37
+ alias_method :refresh_access!, :authorize!
38
+
36
39
  end
37
40
  end
38
41
  end
@@ -1,5 +1,6 @@
1
1
  module Redd
2
2
  # An error from reddit
3
+ # TODO: Move Error to an Errors module in next minor version?
3
4
  class Error < StandardError
4
5
  attr_reader :code
5
6
  attr_reader :headers
@@ -27,7 +28,7 @@ module Redd
27
28
  when /wrong_password/i then InvalidCredentials
28
29
  when /bad_captcha/i then InvalidCaptcha
29
30
  when /ratelimit/i then RateLimited
30
- when /quota_filled/i then RateLimited
31
+ when /quota_filled/i then QuotaFilled
31
32
  when /bad_css_name/i then InvalidClassName
32
33
  when /too_old/i then Archived
33
34
  when /too_much_flair_css/i then TooManyClassNames
@@ -104,6 +105,9 @@ module Redd
104
105
  # You don't have the proper scope to perform this request.
105
106
  InvalidScope = Class.new(Error)
106
107
 
108
+ # Looks like we didn't get a JSON response. Raise this error.
109
+ JSONError = Class.new(Error)
110
+
107
111
  # Four, oh four! The thing you're looking for wasn't found.
108
112
  NotFound = Class.new(Error)
109
113
 
@@ -121,8 +125,16 @@ module Redd
121
125
  attr_reader :time
122
126
 
123
127
  def initialize(env)
124
- @time = env[:body][:json][:ratelimit] || 60*60
125
128
  super
129
+ @time = env[:body][:json][:ratelimit] || 3600
130
+ end
131
+ end
132
+
133
+ # This seems to be a more OAuth2-focused error.
134
+ class QuotaFilled < RateLimited
135
+ def initialize(env)
136
+ super
137
+ @time = 3600
126
138
  end
127
139
  end
128
140
 
@@ -1,4 +1,5 @@
1
1
  require "faraday/response"
2
+ require_relative "../error"
2
3
 
3
4
  module Redd
4
5
  # The module that contains middleware that alters the Faraday response.
@@ -7,10 +8,10 @@ module Redd
7
8
  class ParseJson < Faraday::Response::Middleware
8
9
  dependency "multi_json"
9
10
 
10
- def parse(body)
11
- MultiJson.load(body, symbolize_keys: true)
11
+ def on_complete(env)
12
+ env[:body] = MultiJson.load(env[:body], symbolize_keys: true)
12
13
  rescue MultiJson::ParseError
13
- body
14
+ raise JSONError.new(env), env[:body]
14
15
  end
15
16
  end
16
17
  end
@@ -1,4 +1,4 @@
1
1
  module Redd # rubocop:disable Style/Documentation
2
2
  # The semantic version number.
3
- VERSION = "0.7.7"
3
+ VERSION = "0.7.8"
4
4
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(/^(test|spec|features)\//)
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.9.4"
21
+ spec.add_development_dependency "bundler", "~> 1.10.6"
22
22
  spec.add_development_dependency "rake", "~> 10.4.2"
23
23
  spec.add_development_dependency "rspec", "~> 3.2.0"
24
24
  spec.add_development_dependency "vcr", "~> 2.9.3"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avinash Dwarapu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-30 00:00:00.000000000 Z
11
+ date: 2015-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.9.4
19
+ version: 1.10.6
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.9.4
26
+ version: 1.10.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -194,7 +194,6 @@ files:
194
194
  - lib/redd/version.rb
195
195
  - redd.gemspec
196
196
  - spec/redd/objects/base_spec.rb
197
- - spec/redd/response/parse_json_spec.rb
198
197
  - spec/redd/response/raise_error_spec.rb
199
198
  - spec/redd_spec.rb
200
199
  - spec/spec_helper.rb
@@ -218,13 +217,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
217
  version: '0'
219
218
  requirements: []
220
219
  rubyforge_project:
221
- rubygems_version: 2.4.5
220
+ rubygems_version: 2.4.7
222
221
  signing_key:
223
222
  specification_version: 4
224
223
  summary: A Reddit API Wrapper for Ruby.
225
224
  test_files:
226
225
  - spec/redd/objects/base_spec.rb
227
- - spec/redd/response/parse_json_spec.rb
228
226
  - spec/redd/response/raise_error_spec.rb
229
227
  - spec/redd_spec.rb
230
228
  - spec/spec_helper.rb
@@ -1,12 +0,0 @@
1
- RSpec.describe Redd::Response::ParseJson do
2
- it "parses valid JSON" do
3
- parsed = subject.parse('{"hello": "world", "foo": {"bar": 2}}')
4
- expect(parsed).to eq(hello: "world", foo: {bar: 2})
5
- end
6
-
7
- it "returns the JSON string if it's invalid" do
8
- error = "comparision with banana failed."
9
- parsed = subject.parse(error)
10
- expect(parsed).to eq(error)
11
- end
12
- end