reddit_api 0.1.8 → 0.1.9

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
2
  SHA1:
3
- metadata.gz: eacde9ea333bc1315373a0f290206b732cb1e96e
4
- data.tar.gz: 0dc362bbfab3646ef24e11e51e39d5b2f88cc63e
3
+ metadata.gz: 695f6cabfc01e4d67dd792e8a4310420c384d4cf
4
+ data.tar.gz: 75f4d2b68c25333749a7693b79513a2cbe2b5bbc
5
5
  SHA512:
6
- metadata.gz: e46812d6b27e48366bc7d1e91734c25b3b005597c18f8ccba4b084cbf510350b60f5be72c016580be8fc6b4a278a1cc95db2e0a9d3a577cad6e84f20683bc55b
7
- data.tar.gz: 4e53b63d37610ae05f25907ee3cf4316002734103ffbae6d77ce00086b8bcbaf2bcb8e9ce3e555801a680ca271850dcb64c89c878c341a940e02a655c0406909
6
+ metadata.gz: a41131435f118405286bad1fc923c0b180dc017716734d3e61664887d9428a0c40195f24cd41a28978b27c50f1a0bae5b49101863f10299d0395e05b4b061604
7
+ data.tar.gz: 0d394fa9542b1bd14f5921391915c91fa53f73b51d2ae762ea5ea1ba3c74cdea3e607e12cc48e97f60c5514f5be0e10863ad6425f274344c9e6d44aca7329a05
@@ -2,71 +2,71 @@
2
2
  module RedditApi
3
3
  class Requestor
4
4
 
5
- MAXIMUM_RECORDS = 100
6
- AGENT = ENV["REDDIT_AGENT"]
7
- ID = ENV["REDDIT_ID"]
8
- PASSWORD = ENV["REDDIT_PASSWORD"]
9
- SECRET = ENV["REDDIT_SECRET"]
10
- USERNAME = ENV["REDDIT_USERNAME"]
11
- BASE_URL = "https://oauth.reddit.com/"
5
+ MAXIMUM_RECORDS = 100
12
6
 
13
- def initialize(args = {})
14
- @client = args.fetch(:client, HTTParty)
15
- end
7
+ def initialize(args = {})
8
+ @client = args.fetch(:client, HTTParty)
9
+ @agent = ENV["REDDIT_AGENT"]
10
+ @id = ENV["REDDIT_ID"]
11
+ @password = ENV["REDDIT_PASSWORD"]
12
+ @secret = ENV["REDDIT_SECRET"]
13
+ @username = ENV["REDDIT_USERNAME"]
14
+ @base_url = "https://oauth.reddit.com/"
15
+ end
16
16
 
17
- def build(endpoint, resource_type, last_record = nil)
18
- url = BASE_URL + endpoint
19
- headers = generate_headers
20
- query = generate_query(resource_type, last_record)
21
- [url, { headers: headers, query: query }]
22
- end
17
+ def build(endpoint, resource_type, last_record = nil)
18
+ url = base_url + endpoint
19
+ headers = generate_headers
20
+ query = generate_query(resource_type, last_record)
21
+ [url, { headers: headers, query: query }]
22
+ end
23
23
 
24
- private
25
- attr_reader :client
24
+ private
25
+ attr_reader :agent, :base_url, :id, :password, :secret, :username, :client
26
26
 
27
- def generate_headers
28
- access_token = generate_access_token
29
- {
30
- "Authorization" => "bearer #{access_token}",
31
- "user-agent" => AGENT
32
- }
33
- end
27
+ def generate_headers
28
+ access_token = generate_access_token
29
+ {
30
+ "Authorization" => "bearer #{access_token}",
31
+ "user-agent" => agent
32
+ }
33
+ end
34
34
 
35
- def generate_query(resource_type, last_record)
36
- {
37
- limit: MAXIMUM_RECORDS,
38
- after: generate_after(resource_type, last_record)
39
- }
40
- end
35
+ def generate_query(resource_type, last_record)
36
+ {
37
+ limit: MAXIMUM_RECORDS,
38
+ after: generate_after(resource_type, last_record)
39
+ }
40
+ end
41
41
 
42
- def generate_after(resource_type, last_record)
43
- if last_record
44
- build_after(resource_type, last_record)
45
- else
46
- ""
47
- end
42
+ def generate_after(resource_type, last_record)
43
+ if last_record
44
+ build_after(resource_type, last_record)
45
+ else
46
+ ""
48
47
  end
48
+ end
49
49
 
50
- def build_after(resource_type, record)
51
- prefix = TYPE_PREFIXES[resource_type]
52
- last_resource_id = record["data"]["id"]
53
- "#{prefix}_#{last_resource_id}"
54
- end
50
+ def build_after(resource_type, record)
51
+ prefix = TYPE_PREFIXES[resource_type]
52
+ last_resource_id = record["data"]["id"]
53
+ "#{prefix}_#{last_resource_id}"
54
+ end
55
55
 
56
- def generate_access_token
57
- url = "https://www.reddit.com/api/v1/access_token"
58
- basic_auth = { username: ID,
59
- password: SECRET }
60
- headers = { "user-agent" => AGENT }
61
- body = { grant_type: "password",
62
- username: USERNAME,
63
- password: PASSWORD }
64
- response = client.post(url,
65
- basic_auth: basic_auth,
66
- headers: headers,
67
- body: body)
68
- response["access_token"]
69
- end
56
+ def generate_access_token
57
+ url = "https://www.reddit.com/api/v1/access_token"
58
+ basic_auth = { username: id,
59
+ password: secret }
60
+ headers = { "user-agent" => agent }
61
+ body = { grant_type: "password",
62
+ username: username,
63
+ password: password }
64
+ response = client.post(url,
65
+ basic_auth: basic_auth,
66
+ headers: headers,
67
+ body: body)
68
+ response["access_token"]
69
+ end
70
70
 
71
71
  end
72
72
  end
@@ -1,3 +1,3 @@
1
1
  module RedditApi
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reddit_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Fuentes