hunting_season 0.0.1 → 0.0.2
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 +8 -8
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/VERSION +1 -0
- data/lib/hunting_season.rb +5 -0
- data/lib/product_hunt/api.rb +11 -45
- data/lib/product_hunt/api/comment.rb +13 -0
- data/lib/product_hunt/api/post.rb +86 -0
- data/lib/product_hunt/api/user.rb +24 -0
- data/lib/product_hunt/api/vote.rb +15 -0
- metadata +26 -7
- data/spec/product_hunt_spec.rb +0 -37
- data/spec/spec_helper.rb +0 -8
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTQ5MzhkZTE2MGE3MzI3ODFmMzBjYmVlNjNiNmQwN2U4NTQxMTRhMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTc1NTFhOGQ1OTUwMjI2YzRhYmVmMzAxMDExMzRkNzJjYzJlNzhhNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjI1OWI4Y2ZmNWNjMDBlMjNmODNkZDQ4MDM3MzQzZTIxYTIwNGM5NmI0MzM4
|
10
|
+
ODkyNzRkMDY1OTcwNTM0MmNlZjYzNTExMGJiM2I3NGEwMTIwNmU1YmE5MmE1
|
11
|
+
YWI3Y2E4OWMwOWM5ZGEzYzNjMzhhY2M1MDMwN2NkNzc1NTljNjQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjcxYjc5YjZmYjBjYTc2NDUxZDc2MjQ0ZjlmNmQxZDAyMDc0ZTJmNDc2MGIy
|
14
|
+
YmM2MDA2MzU5NGVmMjNiNjVjMzU5OThhMTVlMzA5NjNjZjE0MTlkYmNhZTUy
|
15
|
+
ZjFjNDQyMWM4Y2JiNGQwZGJhNDhmNDgxYTIxOTIyYzMwNWFiODk=
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Mike Jarema
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# hunting_season [](http://travis-ci.org/mikejarema/hunting_season)
|
2
|
+
|
3
|
+
Ruby gem for interacting with the official [Product Hunt API](https://api.producthunt.com/v1/docs).
|
4
|
+
|
5
|
+
|
6
|
+
## Authentication
|
7
|
+
|
8
|
+
Currently only supports a single token, passed to `ProductHunt::API.new(token)`. This mainly supports the use case of using the _Developer Token_ which can be created in the API Dashboard.
|
9
|
+
|
10
|
+
|
11
|
+
## Supported Endpoints
|
12
|
+
|
13
|
+
* [posts#show - Get details of a post](https://api.producthunt.com/v1/docs/posts/posts_show_get_details_of_a_post)
|
14
|
+
* [votes#index - See all votes for a post](https://api.producthunt.com/v1/docs/postvotes/votes_index_see_all_votes_for_a_post)
|
15
|
+
* [users#show - Get details of a user](https://api.producthunt.com/v1/docs/users/users_show_get_details_of_a_user)
|
16
|
+
|
17
|
+
|
18
|
+
### In Progress
|
19
|
+
|
20
|
+
* [comments#index - Fetch all comments of a post](https://api.producthunt.com/v1/docs/comments/comments_index_fetch_all_comments_of_a_post)
|
21
|
+
|
22
|
+
|
23
|
+
## Examples
|
24
|
+
|
25
|
+
For now, see `product_hunt_spec.rb` for examples covering each of the supported endpoints.
|
26
|
+
|
27
|
+
|
28
|
+
## Miscellany
|
29
|
+
|
30
|
+
Legal: see LICENSE
|
31
|
+
|
32
|
+
Quick shout out to [Katchphraze](http://on.rdio.com/1zEb5cA) for unintentionally naming this gem 7 years later :headphones:
|
33
|
+
|
34
|
+
Copyright (c) 2014 Mike Jarema
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/lib/hunting_season.rb
CHANGED
data/lib/product_hunt/api.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# TODO: factor out a base class btw User and Post
|
2
|
+
|
1
3
|
require 'httparty'
|
2
4
|
require 'uri'
|
3
5
|
|
@@ -18,56 +20,20 @@ module ProductHunt
|
|
18
20
|
def posts(options_or_id_or_nil = nil)
|
19
21
|
if options_or_id_or_nil.is_a?(Fixnum)
|
20
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)
|
21
27
|
else
|
22
28
|
raise InvalidArgumentError.new("#{options_or_id_or_nil} is not supported by ProductHunt::API#posts")
|
23
29
|
end
|
24
30
|
end
|
25
31
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
self
|
32
|
-
end
|
33
|
-
|
34
|
-
def [](key)
|
35
|
-
if @attributes.nil?
|
36
|
-
fetch_self
|
37
|
-
end
|
38
|
-
@attributes[key]
|
39
|
-
end
|
40
|
-
|
41
|
-
def votes(options = {})
|
42
|
-
if @id
|
43
|
-
fetch_votes(options).map{|i| Vote.new(@api, i)}
|
44
|
-
else
|
45
|
-
raise InvalidCallError.new("Cannot call ProductHunt::Post#votes on an unsaved or uninitialized Post")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def fetch_self
|
52
|
-
@attributes = @api.class.get("/posts/#{@id}", @api.config)["post"]
|
53
|
-
end
|
54
|
-
|
55
|
-
def fetch_votes(params)
|
56
|
-
path = "/posts/#{@id}/votes"
|
57
|
-
if params.is_a?(Enumerable)
|
58
|
-
path += "?" + URI.encode_www_form(params)
|
59
|
-
end
|
60
|
-
@api.class.get(path, @api.config)["votes"]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
class Vote
|
65
|
-
def initialize(api, attributes)
|
66
|
-
@attributes = attributes
|
67
|
-
end
|
68
|
-
|
69
|
-
def [](key)
|
70
|
-
@attributes[key]
|
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")
|
71
37
|
end
|
72
38
|
end
|
73
39
|
|
@@ -0,0 +1,86 @@
|
|
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
|
@@ -0,0 +1,24 @@
|
|
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
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Jarema
|
@@ -44,25 +44,44 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2'
|
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: '
|
55
|
-
|
56
|
-
|
54
|
+
version: '2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-todo
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: This gem is a work-in-progress which allows for calls to some of the
|
70
|
+
offical API's endpoints (see README).
|
57
71
|
email: mike@jarema.com
|
58
72
|
executables: []
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
- VERSION
|
62
79
|
- lib/hunting_season.rb
|
63
80
|
- lib/product_hunt/api.rb
|
64
|
-
-
|
65
|
-
-
|
81
|
+
- lib/product_hunt/api/comment.rb
|
82
|
+
- lib/product_hunt/api/post.rb
|
83
|
+
- lib/product_hunt/api/user.rb
|
84
|
+
- lib/product_hunt/api/vote.rb
|
66
85
|
homepage: http://rubygems.org/gems/hunting_season
|
67
86
|
licenses:
|
68
87
|
- MIT
|
data/spec/product_hunt_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ProductHunt do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@api = ProductHunt::API.new(ENV['TOKEN'] || 'my-token')
|
7
|
-
end
|
8
|
-
|
9
|
-
describe 'API::Post' do
|
10
|
-
|
11
|
-
before(:each) do
|
12
|
-
@post = @api.posts(3372)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'implements posts#show and yields the name of the post' do
|
16
|
-
@post['name'].should == 'namevine'
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'implements votes#index and yields the first voter' do
|
20
|
-
vote = @post.votes.first
|
21
|
-
|
22
|
-
vote.should be_a(ProductHunt::API::Vote)
|
23
|
-
vote['user']['username'].should == '1korda'
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'implements votes#index with pagination' do
|
27
|
-
votes = @post.votes(per_page: 1)
|
28
|
-
votes.size.should be(1)
|
29
|
-
|
30
|
-
votes = @post.votes(per_page: 1, older: votes.first['id'])
|
31
|
-
votes.size.should be(1)
|
32
|
-
votes.first['user']['username'].should == 'mikejarema'
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|