reddit-base 0.3.0 → 0.3.1

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: f3fb4e405bfd23bc1f041840b615db26dadf957c
4
- data.tar.gz: 7185a75f8c788884d0fecb1307f8a6fa5e3e1c90
3
+ metadata.gz: 04b8cd781236070038145739f35ad484bbb7c3c1
4
+ data.tar.gz: ff98d9f539a4fddbe7ccd5b299afae68f266c67a
5
5
  SHA512:
6
- metadata.gz: 53c19842b951b856aa5b4ed7b7f5354c715deca5b97dc60a2628ac503e436d28f77a562b34bbb88453d6debdc0ba13a03e45ee1ce21fc1450f613ed805da4de5
7
- data.tar.gz: ed6a28235b15a55a88ec24ca935eab60d9a43acbc6493b6e4d4a00b1a08f90a1f5d43696875f41503620200315b0aac7e30539c90518d6c1b5d37f2923bf0e3f
6
+ metadata.gz: 5f61050f2f8dac84d0ae6c7b0cb8513917d2b6d4195646b7ddb116f975df623caa7a949e2a01379abf9b82a06a0d9bc4daff5a425f99ff6edbdfbfd6ea6a8ad8
7
+ data.tar.gz: d3798e08febb37b6833bb4794d411e335c7430d9472108e23d449bfa9ebe2a3c2c5be236b460d32df998ed7363acb7e727886daa0a266408126428201674f4be
data/README.md CHANGED
@@ -28,8 +28,27 @@ Or in your Gemfile with Bundler:
28
28
  gem reddit-base
29
29
  ```
30
30
 
31
- Basic Usage
32
- -------------
31
+ What it Does
32
+ ------------
33
+
34
+ * Authentication (user/password, cookie, OAuth2 access token).
35
+ * Rate limiting.
36
+ * Modhash handling (reddit's CSRF protection).
37
+ * JSON coersion.
38
+ * Forwarding..
39
+ * Multipart POST.
40
+ * Reddit error wrapping.
41
+
42
+ What it Doesn't
43
+ ---------------
44
+
45
+ * OAuth2 token negotiation.
46
+ * Parsing of Reddit "Things" and "Kinds."
47
+ * Parsing of common attributes like dates and times.
48
+ * HTML entity decoding (beware of "body" and "selftext").
49
+
50
+ Usage
51
+ -----
33
52
 
34
53
  Retrieve the JSON for a particular endpoint:
35
54
 
@@ -50,14 +69,9 @@ client.get('/r/AskReddit') # Need to make at least one GET request to retrieve a
50
69
  client.post('/api/submit', kind: 'self', sr: SUBREDDIT, title: 'Hello,', text: 'World!')
51
70
  ```
52
71
 
53
- `Client#get` and `Client#post` accept a `simplify` option to flatten data and kind attributes
54
- for easier traversal:
55
-
56
- ```ruby
57
- client.get('/r/AskReddit', simplify: true)
58
- ```
72
+ ### Authentication
59
73
 
60
- Several forms of authentication are supported:
74
+ Examples:
61
75
 
62
76
  ```ruby
63
77
  # Username and password.
@@ -70,24 +84,23 @@ client = Reddit::Base::Client.new(cookie: COOKIE)
70
84
  client = Reddit::Base::Client.new(access_token: ACCESS_TOKEN)
71
85
  ```
72
86
 
73
- What it Does
74
- ------------
87
+ ### File Uploads
75
88
 
76
- * Authentication (user/password, cookie, OAuth2 access token).
77
- * Rate limiting.
78
- * Modhash handling (reddit's CSRF protection).
79
- * JSON coersion.
80
- * Forwarding..
81
- * Multipart POST.
82
- * Reddit error wrapping.
89
+ For example, uploading an image to a subreddit you moderate:
83
90
 
84
- What it Doesn't
85
- ---------------
91
+ ```ruby
92
+ image_upload = Reddit::Base::UploadIO.new('/path/to/your/image.png', 'image/png')
93
+ reddit.post('/api/upload_sr_img.json', r: SUBREDDIT, file: image_upload, header: 0, name: 'example'
94
+ ```
86
95
 
87
- * OAuth2 token negotiation.
88
- * Parsing of Reddit "Things" and "Kinds."
89
- * Parsing of common attributes like dates and times.
90
- * HTML entity decoding (beware of "body" and "selftext").
96
+ ### Helpers
97
+
98
+ `Client#get` and `Client#post` accept a `simplify` option to flatten data and kind attributes
99
+ for easier traversal:
100
+
101
+ ```ruby
102
+ client.get('/r/AskReddit', simplify: true)
103
+ ```
91
104
 
92
105
  Recommended Reading
93
106
  -------------------
data/lib/reddit/base.rb CHANGED
@@ -7,6 +7,7 @@ require 'reddit/base/version'
7
7
  require 'reddit/base/basic_client'
8
8
  require 'reddit/base/client'
9
9
  require 'reddit/base/helpers'
10
+ require 'reddit/base/upload_io'
10
11
 
11
12
  module Reddit
12
13
  module Base
@@ -8,9 +8,13 @@ module Reddit
8
8
  class BasicClient
9
9
  extend Forwardable
10
10
 
11
+ DEFAULT_URL = 'http://www.reddit.com'.freeze
12
+ DEFAULT_URL_SECURE = 'https://ssl.reddit.com'.freeze
13
+
11
14
  DEFAULT_OPTIONS = {
12
- url: 'http://www.reddit.com',
13
- headers: {'User-Agent' => "reddit-base, a reddit client for ruby by /u/dobs (v#{VERSION})"}
15
+ headers: {'User-Agent' => "reddit-base, a reddit client for ruby by /u/dobs (v#{VERSION})"},
16
+ rem: true,
17
+ url: DEFAULT_URL
14
18
  }.freeze
15
19
 
16
20
  attr_reader :connection, :options
@@ -18,7 +22,10 @@ module Reddit
18
22
  def_delegators :connection, :get, :post, :params, :headers
19
23
 
20
24
  def initialize(options)
25
+ @secure = options.delete(:secure)
26
+
21
27
  @options = DEFAULT_OPTIONS.merge(options)
28
+ @options[:url] = DEFAULT_URL_SECURE if @secure
22
29
  @connection = Faraday.new(url: @options[:url], headers: @options[:headers]) do |builder|
23
30
  builder.request :multipart
24
31
  builder.request :url_encoded
@@ -11,14 +11,16 @@ module Reddit
11
11
  end
12
12
 
13
13
  def get(*args, **options)
14
+ simplify = options.delete(:simplify)
14
15
  body = connection.get(*args, **options).body
15
- body = Reddit::Base::Helpers.simplify body if options[:simplify]
16
+ body = Reddit::Base::Helpers.simplify body if simplify
16
17
  body
17
18
  end
18
19
 
19
20
  def post(*args, **options)
21
+ simplify = options.delete(:simplify)
20
22
  body = connection.post(*args, **options).body
21
- body = Reddit::Base::Helpers.simplify body if options[:simplify]
23
+ body = Reddit::Base::Helpers.simplify body if simplify
22
24
  body
23
25
  end
24
26
  end
@@ -0,0 +1,5 @@
1
+ module Reddit
2
+ module Base
3
+ UploadIO = ::Faraday::UploadIO
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Reddit
2
2
  module Base
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
5
5
  end
data/reddit-base.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["dan@dobs.org"]
11
11
  spec.summary = %q{A minimal reddit API client for Ruby.}
12
12
  spec.description = %q{A minimal reddit API client for Ruby that
13
- simplifies concerns such authentication, rate limiting and extracting
13
+ simplifies concerns such as authentication, rate limiting and extracting
14
14
  JSON.}
15
15
  spec.homepage = ""
16
16
  spec.license = "MIT"
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.5"
25
25
  spec.add_development_dependency "rake"
26
26
 
27
- spec.add_dependency 'faraday_middleware-reddit', '0.3.0'
27
+ spec.add_dependency 'faraday_middleware-reddit', '0.3.1'
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reddit-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel O'Brien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-25 00:00:00.000000000 Z
11
+ date: 2014-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,17 +44,17 @@ dependencies:
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.0
47
+ version: 0.3.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.3.0
54
+ version: 0.3.1
55
55
  description: |-
56
56
  A minimal reddit API client for Ruby that
57
- simplifies concerns such authentication, rate limiting and extracting
57
+ simplifies concerns such as authentication, rate limiting and extracting
58
58
  JSON.
59
59
  email:
60
60
  - dan@dobs.org
@@ -71,6 +71,7 @@ files:
71
71
  - lib/reddit/base/basic_client.rb
72
72
  - lib/reddit/base/client.rb
73
73
  - lib/reddit/base/helpers.rb
74
+ - lib/reddit/base/upload_io.rb
74
75
  - lib/reddit/base/version.rb
75
76
  - reddit-base.gemspec
76
77
  homepage: ''
@@ -93,9 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
94
  version: '0'
94
95
  requirements: []
95
96
  rubyforge_project:
96
- rubygems_version: 2.2.2
97
+ rubygems_version: 2.0.3
97
98
  signing_key:
98
99
  specification_version: 4
99
100
  summary: A minimal reddit API client for Ruby.
100
101
  test_files: []
101
- has_rdoc: