hunting_season 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/lib/hunting_season.rb +10 -4
- data/lib/product_hunt/api.rb +3 -38
- data/lib/product_hunt/api/posts.rb +25 -0
- data/lib/product_hunt/api/users.rb +14 -0
- data/lib/product_hunt/client.rb +28 -0
- data/lib/product_hunt/comment.rb +5 -0
- data/lib/product_hunt/{api/comment.rb → entity.rb} +4 -3
- data/lib/product_hunt/post.rb +30 -0
- data/lib/product_hunt/user.rb +7 -0
- data/lib/product_hunt/vote.rb +6 -0
- metadata +18 -13
- data/lib/product_hunt/api/post.rb +0 -86
- data/lib/product_hunt/api/user.rb +0 -24
- data/lib/product_hunt/api/vote.rb +0 -15
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmM2YmY1YzFkZDlkMDE3MzdlNjFjZjdhOTZlOTY0MjE5OTE4ZGNiNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjdmZDY5MzE5ODQ3NWQ5NWQ3YzllOTcwNmYyYTg0ODAwZTI2ZDdlOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDM5ZjNmODIxNDBlMzU2N2I5NjllNTg3MzljMzY5YmQwMjkzNzk0YzRjMzUz
|
10
|
+
Y2FmYzU3MjZiM2M5YzExZTE2NjUwN2VmOWNmMTJiMTk3NDA0MTE2ZDc3OWVj
|
11
|
+
MWQzNGUwM2M2YzczODRjMTc3ZWE3MmY5Zjc1ZGIxYzUwMjZhMDI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTc2ZWMyNzAwZDQ5MmZhNmExMzc1ZGFkZTExNmNhYjU5NWVjNGQ0YWI2YmI4
|
14
|
+
N2JhZDA5ODY3N2ZjNzZlNTFlNTJhNTNiZTM1ZTQ0ZDhjYTg2ZjMyM2YzMDZm
|
15
|
+
M2RjYjEyMmE0Y2YzODYzOWNjZDIzMGI3YmJiMDlmMmMzMmExNTE=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/lib/hunting_season.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
require 'product_hunt/api/users'
|
2
|
+
require 'product_hunt/api/posts'
|
3
|
+
|
1
4
|
require 'product_hunt/api'
|
5
|
+
require 'product_hunt/client'
|
6
|
+
|
7
|
+
require 'product_hunt/entity'
|
8
|
+
require 'product_hunt/user'
|
9
|
+
require 'product_hunt/post'
|
10
|
+
require 'product_hunt/vote'
|
11
|
+
require 'product_hunt/comment'
|
2
12
|
|
3
|
-
require 'product_hunt/api/user'
|
4
|
-
require 'product_hunt/api/post'
|
5
|
-
require 'product_hunt/api/vote'
|
6
|
-
require 'product_hunt/api/comment'
|
data/lib/product_hunt/api.rb
CHANGED
@@ -1,43 +1,8 @@
|
|
1
1
|
# TODO: factor out a base class btw User and Post
|
2
2
|
|
3
|
-
require 'httparty'
|
4
|
-
require 'uri'
|
5
|
-
|
6
3
|
module ProductHunt
|
7
|
-
|
8
|
-
include
|
9
|
-
|
10
|
-
format :json
|
11
|
-
|
12
|
-
def initialize(token)
|
13
|
-
@config = { headers: { "Authorization" => "Bearer #{token}" } }
|
14
|
-
end
|
15
|
-
|
16
|
-
def config
|
17
|
-
@config
|
18
|
-
end
|
19
|
-
|
20
|
-
def posts(options_or_id_or_nil = nil)
|
21
|
-
if options_or_id_or_nil.is_a?(Fixnum)
|
22
|
-
post = Post.new(self, options_or_id_or_nil)
|
23
|
-
elsif options_or_id_or_nil.nil?
|
24
|
-
Post.where(self, {})
|
25
|
-
elsif options_or_id_or_nil.is_a?(Hash)
|
26
|
-
Post.where(self, options_or_id_or_nil)
|
27
|
-
else
|
28
|
-
raise InvalidArgumentError.new("#{options_or_id_or_nil} is not supported by ProductHunt::API#posts")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def users(id)
|
33
|
-
if id.is_a?(Fixnum) || id.is_a?(String)
|
34
|
-
post = User.new(self, id)
|
35
|
-
else
|
36
|
-
raise InvalidArgumentError.new("#{id} is not supported by ProductHunt::API#users")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class InvalidArgumentError < ArgumentError; end
|
41
|
-
class InvalidCallError < RuntimeError; end
|
4
|
+
module API
|
5
|
+
include ProductHunt::API::Posts
|
6
|
+
include ProductHunt::API::Users
|
42
7
|
end
|
43
8
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ProductHunt
|
2
|
+
module API
|
3
|
+
module Posts
|
4
|
+
|
5
|
+
PATH = "/posts"
|
6
|
+
|
7
|
+
def posts(options = {})
|
8
|
+
fetch(PATH, options)["posts"].map{ |post| Post.new(post, self) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def post(id, options = {})
|
12
|
+
post = fetch(PATH + "/#{id}", options)["post"]
|
13
|
+
Post.new(post, self)
|
14
|
+
end
|
15
|
+
|
16
|
+
def comments_for_post(id, options = {})
|
17
|
+
fetch(PATH + "/#{id}/comments", options)["comments"].map{ |c| Comment.new(c, self) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def votes_for_post(id, options = {})
|
21
|
+
fetch(PATH + "/#{id}/votes", options)["votes"].map{ |c| Vote.new(c, self) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module ProductHunt
|
5
|
+
class Client
|
6
|
+
include HTTParty
|
7
|
+
base_uri 'https://api.producthunt.com/v1/'
|
8
|
+
format :json
|
9
|
+
|
10
|
+
include ProductHunt::API
|
11
|
+
|
12
|
+
def initialize(token)
|
13
|
+
@config = { headers: { "Authorization" => "Bearer #{token}" } }
|
14
|
+
end
|
15
|
+
|
16
|
+
def config
|
17
|
+
@config
|
18
|
+
end
|
19
|
+
|
20
|
+
def fetch(path, params)
|
21
|
+
queryopts = if params.is_a?(Enumerable) && params.size > 0
|
22
|
+
"?" + URI.encode_www_form(params)
|
23
|
+
end
|
24
|
+
|
25
|
+
self.class.get(path + (queryopts || ""), @config)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,13 +1,14 @@
|
|
1
1
|
module ProductHunt
|
2
|
+
module Entity
|
2
3
|
|
3
|
-
|
4
|
-
def initialize(api, attributes)
|
4
|
+
def initialize(attributes, client)
|
5
5
|
@attributes = attributes
|
6
|
+
@client = client
|
6
7
|
end
|
7
8
|
|
8
9
|
def [](key)
|
9
10
|
@attributes[key]
|
10
11
|
end
|
11
|
-
end
|
12
12
|
|
13
|
+
end
|
13
14
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module ProductHunt
|
2
|
+
class Post
|
3
|
+
include Entity
|
4
|
+
|
5
|
+
def created_at
|
6
|
+
Time.parse(self["created_at"])
|
7
|
+
end
|
8
|
+
|
9
|
+
def day
|
10
|
+
Time.parse(self["day"]).to_date
|
11
|
+
end
|
12
|
+
|
13
|
+
def votes(options = {})
|
14
|
+
if options != @votes_options
|
15
|
+
@votes = @client.votes_for_post(self["id"], options)
|
16
|
+
@votes_options = options
|
17
|
+
end
|
18
|
+
@votes
|
19
|
+
end
|
20
|
+
|
21
|
+
def comments(options = {})
|
22
|
+
if options != @comments_options
|
23
|
+
@comments = @client.comments_for_post(self["id"], options)
|
24
|
+
@comments_options = options
|
25
|
+
end
|
26
|
+
@comments
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hunting_season
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Jarema
|
@@ -44,30 +44,31 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3'
|
48
48
|
type: :development
|
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: '
|
54
|
+
version: '3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: webmock
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
-
description:
|
70
|
-
offical API's
|
68
|
+
version: '1'
|
69
|
+
description: Ruby gem which interfaces with Product Hunt's official REST API (api.producthunt.com).
|
70
|
+
This gem is a work-in-progress which allows for calls to some of the offical API's
|
71
|
+
endpoints (see README).
|
71
72
|
email: mike@jarema.com
|
72
73
|
executables: []
|
73
74
|
extensions: []
|
@@ -78,10 +79,14 @@ files:
|
|
78
79
|
- VERSION
|
79
80
|
- lib/hunting_season.rb
|
80
81
|
- lib/product_hunt/api.rb
|
81
|
-
- lib/product_hunt/api/
|
82
|
-
- lib/product_hunt/api/
|
83
|
-
- lib/product_hunt/
|
84
|
-
- lib/product_hunt/
|
82
|
+
- lib/product_hunt/api/posts.rb
|
83
|
+
- lib/product_hunt/api/users.rb
|
84
|
+
- lib/product_hunt/client.rb
|
85
|
+
- lib/product_hunt/comment.rb
|
86
|
+
- lib/product_hunt/entity.rb
|
87
|
+
- lib/product_hunt/post.rb
|
88
|
+
- lib/product_hunt/user.rb
|
89
|
+
- lib/product_hunt/vote.rb
|
85
90
|
homepage: http://rubygems.org/gems/hunting_season
|
86
91
|
licenses:
|
87
92
|
- MIT
|
@@ -105,5 +110,5 @@ rubyforge_project:
|
|
105
110
|
rubygems_version: 2.2.2
|
106
111
|
signing_key:
|
107
112
|
specification_version: 4
|
108
|
-
summary: Ruby
|
113
|
+
summary: Ruby interface to producthunt.com's offical REST API.
|
109
114
|
test_files: []
|
@@ -1,86 +0,0 @@
|
|
1
|
-
module ProductHunt
|
2
|
-
class API::Post
|
3
|
-
|
4
|
-
def initialize(api, id_or_attributes)
|
5
|
-
@api = api
|
6
|
-
|
7
|
-
if id_or_attributes.is_a?(Hash)
|
8
|
-
@id = id_or_attributes["id"]
|
9
|
-
@attributes = id_or_attributes
|
10
|
-
else
|
11
|
-
@id = id_or_attributes
|
12
|
-
@attributes = nil
|
13
|
-
end
|
14
|
-
|
15
|
-
self
|
16
|
-
end
|
17
|
-
|
18
|
-
def [](key)
|
19
|
-
if @attributes.nil?
|
20
|
-
fetch_self
|
21
|
-
end
|
22
|
-
@attributes[key]
|
23
|
-
end
|
24
|
-
|
25
|
-
def votes(options = {})
|
26
|
-
if @id
|
27
|
-
fetch_votes(options).map{|i| API::Vote.new(@api, i)}
|
28
|
-
else
|
29
|
-
raise InvalidCallError.new("Cannot call ProductHunt::Post#votes on an unsaved or uninitialized Post")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def comments(options = {})
|
34
|
-
if @id
|
35
|
-
fetch_comments(options).map{|i| API::Comment.new(@api, i)}
|
36
|
-
else
|
37
|
-
raise InvalidCallError.new("Cannot call ProductHunt::Post#votes on an unsaved or uninitialized Post")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def created_at
|
42
|
-
Time.parse(self["created_at"])
|
43
|
-
end
|
44
|
-
|
45
|
-
def day
|
46
|
-
Time.parse(self["day"]).to_date
|
47
|
-
end
|
48
|
-
|
49
|
-
# Class Methods
|
50
|
-
|
51
|
-
def self.where(api, options)
|
52
|
-
self.fetch_posts(api, options).map{|i| API::Post.new(api, i)}
|
53
|
-
end
|
54
|
-
|
55
|
-
private
|
56
|
-
|
57
|
-
def fetch_self
|
58
|
-
@attributes = @api.class.get("/posts/#{@id}", @api.config)["post"]
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.fetch_posts(api, params)
|
62
|
-
path = "/posts"
|
63
|
-
if params.is_a?(Enumerable)
|
64
|
-
path += "?" + URI.encode_www_form(params)
|
65
|
-
end
|
66
|
-
api.class.get(path, api.config)["posts"]
|
67
|
-
end
|
68
|
-
|
69
|
-
def fetch_votes(params)
|
70
|
-
path = "/posts/#{@id}/votes"
|
71
|
-
if params.is_a?(Enumerable)
|
72
|
-
path += "?" + URI.encode_www_form(params)
|
73
|
-
end
|
74
|
-
@api.class.get(path, @api.config)["votes"]
|
75
|
-
end
|
76
|
-
|
77
|
-
def fetch_comments(params)
|
78
|
-
path = "/posts/#{@id}/comments"
|
79
|
-
if params.is_a?(Enumerable)
|
80
|
-
path += "?" + URI.encode_www_form(params)
|
81
|
-
end
|
82
|
-
@api.class.get(path, @api.config)["comments"]
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module ProductHunt
|
2
|
-
class API::User
|
3
|
-
def initialize(api, id_or_username)
|
4
|
-
@api = api
|
5
|
-
@id_or_username = id_or_username
|
6
|
-
@attributes = nil
|
7
|
-
self
|
8
|
-
end
|
9
|
-
|
10
|
-
def [](key)
|
11
|
-
if @attributes.nil?
|
12
|
-
fetch_self
|
13
|
-
end
|
14
|
-
@attributes[key]
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def fetch_self
|
20
|
-
@attributes = @api.class.get("/users/#{@id_or_username}", @api.config)["user"]
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|