hunting_season 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmM2YmY1YzFkZDlkMDE3MzdlNjFjZjdhOTZlOTY0MjE5OTE4ZGNiNQ==
4
+ MjBhM2U0NmJlYjNmM2FiNDUxY2U4M2FmZGRiZTZlYTQyNjkxM2NiMg==
5
5
  data.tar.gz: !binary |-
6
- ZjdmZDY5MzE5ODQ3NWQ5NWQ3YzllOTcwNmYyYTg0ODAwZTI2ZDdlOQ==
6
+ ZTEyYzI5ZTlhMTcxMmZhZjcwZTdhMTA5MjNlNDQ0M2VlZWE2ZjhhYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDM5ZjNmODIxNDBlMzU2N2I5NjllNTg3MzljMzY5YmQwMjkzNzk0YzRjMzUz
10
- Y2FmYzU3MjZiM2M5YzExZTE2NjUwN2VmOWNmMTJiMTk3NDA0MTE2ZDc3OWVj
11
- MWQzNGUwM2M2YzczODRjMTc3ZWE3MmY5Zjc1ZGIxYzUwMjZhMDI=
9
+ MzA0ODZiMDZhOTBhNDgwNWI3NzBhMTUxYzcyOTkzYzU5MmQ4MGYwNTgxNWE1
10
+ ZTAyZWVmZjJjMDBmZjdjZjJmYTgzMTMwMWVlNDBkMzUwNTExMGEzMDQ0MDY5
11
+ MGM1NGY5OWIyYTA1YTVmMTU4MDc5MjkxZDZmOTI2ZmMwYjY4MGE=
12
12
  data.tar.gz: !binary |-
13
- OTc2ZWMyNzAwZDQ5MmZhNmExMzc1ZGFkZTExNmNhYjU5NWVjNGQ0YWI2YmI4
14
- N2JhZDA5ODY3N2ZjNzZlNTFlNTJhNTNiZTM1ZTQ0ZDhjYTg2ZjMyM2YzMDZm
15
- M2RjYjEyMmE0Y2YzODYzOWNjZDIzMGI3YmJiMDlmMmMzMmExNTE=
13
+ Y2EzYzQ4MTlhMjAwYzgzN2YwMWJmN2Q5ZmU5Mzk0Zjc2ODM4MWEwZWRjZWM3
14
+ MTFhOTVkOTRiN2RmNDk2ZTJiNTFiOWFiYTJlMzIyMmFlNDYwYWFlMzRjYTQw
15
+ ZWI5ZWE4NGM3NDY4NTRhODEwMTcwNTZkZTAwNDNlMWMzMWY1ZjY=
data/README.md CHANGED
@@ -1,34 +1,167 @@
1
1
  # hunting_season [![Build Status](https://secure.travis-ci.org/mikejarema/hunting_season.png)](http://travis-ci.org/mikejarema/hunting_season)
2
2
 
3
- Ruby gem for interacting with the official [Product Hunt API](https://api.producthunt.com/v1/docs).
3
+ `hunting_season` is a ruby gem for interacting with the official [Product Hunt API](https://api.producthunt.com/v1/docs).
4
4
 
5
5
 
6
6
  ## Authentication
7
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.
8
+ `hunting_season` can use any valid API token. Sources include:
9
+
10
+ 1. A `Developer Token` generated in the [Product Hunt API Dashboard](http://www.producthunt.com/v1/oauth/applications).
11
+
12
+ 2. A client OAuth token as generated by [oauth#token - Ask for client level token](https://api.producthunt.com/v1/docs/oauth_client_only_authentication/oauth_token_ask_for_client_level_token).
13
+
14
+ 3. A user OAuth token as generated by [oauth#authorize - Ask for access grant code on behalf of the user](https://api.producthunt.com/v1/docs/oauth_user_authentication/oauth_authorize_ask_for_access_grant_code_on_behalf_of_the_user). See the [omniauth-producthunt gem](https://github.com/lukaszkorecki/omniauth-producthunt) for an Omniauth strategy that may work (I haven't tested it yet).
15
+
16
+ When you have a valid token, simply instantiate the `ProductHunt::Client` as follows:
17
+
18
+ ```
19
+ client = ProductHunt::Client.new('mytoken')
20
+ ```
9
21
 
10
22
 
11
23
  ## Supported Endpoints
12
24
 
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)
25
+ `hunting_season` is a work-in-progress, please [contribute](#contributing) if you need additional functionality.
26
+
27
+
28
+ ### [posts#show - Get details of a post](https://api.producthunt.com/v1/docs/posts/posts_show_get_details_of_a_post)
29
+
30
+ Look up a post using a required numeric ID.
31
+
32
+ Post attributes are listed in the API docs and accessed like `post["name"]`, `post["id"]`, etc.
33
+
34
+ Example:
35
+ ```
36
+ client = ProductHunt::Client.new('mytoken')
37
+
38
+ post = client.post(3372)
39
+ post["name"]
40
+ # => "namevine"
41
+ post["id"]
42
+ # => 3372
43
+ ```
44
+
45
+
46
+ ### [votes#index - See all votes for a post](https://api.producthunt.com/v1/docs/postvotes/votes_index_see_all_votes_for_a_post)
47
+
48
+ Look up a post's votes, with optional ordering and pagination.
49
+
50
+ Post attributes are listed in the API docs and accessed like `vote["user"]`, `vote["id"]`, etc.
51
+
52
+ Example, look up a post's votes and paginate through them in ascending order:
53
+ ```
54
+ client = ProductHunt::Client.new('mytoken')
55
+ post = client.post(3372)
56
+
57
+ votes = post.votes(per_page: 2, order: 'asc')
58
+ votes[0]["id"]
59
+ # => 46164
60
+ "#{votes[0]["user"]["name"]} #{votes[0]["user"]["headline"]}"
61
+ # => "Jack Smith Co-Founded Vungle - Advisor to Coin"
62
+
63
+ votes_page_2 = post.votes(per_page: 2, order: 'asc', newer: votes.last["id"])
64
+ votes_page_2[0]["id"]
65
+ # => 46242
66
+ "#{votes_page_2[0]["user"]["name"]} #{votes_page_2[0]["user"]["headline"]}"
67
+ # => "Helen Crozier Keyboard Karma"
68
+ ```
69
+
70
+
71
+ ### [users#show - Get details of a user](https://api.producthunt.com/v1/docs/users/users_show_get_details_of_a_user)
72
+
73
+ Look up a user by username or id.
74
+
75
+ User attributes are listed in the API docs and accessed like `user["name"]`, `user["headline"]`, etc.
76
+
77
+ Example:
78
+ ```
79
+ client = ProductHunt::Client.new('mytoken')
80
+ user = client.user('rrhoover')
81
+ user["name"]
82
+ # => "Ryan Hoover"
83
+ user["headline"]
84
+ # => "Product Hunt"
85
+ ```
86
+
87
+
88
+ ### [comments#index - Fetch all comments of a post](https://api.producthunt.com/v1/docs/comments/comments_index_fetch_all_comments_of_a_post)
89
+
90
+ Look up a post's comments, with optional ordering and pagination.
91
+
92
+ Example, look up a post's comments and paginate through them in ascending order:
93
+ ```
94
+ client = ProductHunt::Client.new('mytoken')
95
+ post = client.post(3372)
96
+
97
+ comments = post.comments(per_page: 2, order: 'asc')
98
+ comments[0]["id"]
99
+ # => 11378
100
+ "#{comments[0]["user"]["name"]}: #{comments[0]["body"]}"
101
+ # => "Andreas Klinger: fair point but not using thesaurus nor having the ..."
102
+
103
+ comments_page_2 = post.comments(per_page: 2, order: 'asc', newer: comments.last["id"])
104
+ comments_page_2[0]["id"]
105
+ # => 11558
106
+ "#{comments_page_2[0]["user"]["name"]}: #{comments_page_2[0]["body"]}"
107
+ # => "Mike Jarema: Namevine developer here -- feel free to ask any Qs about ..."
108
+ ```
109
+
110
+
111
+ ### Accessing associated records
112
+
113
+ For some API responses, an ID reference to or partial details for an associated User or Post are supplied. `hunting_season` provides convenience methods to access the full details of these associated records.
114
+
115
+ Currently `#post` and `#user` apply when the associated record is present.
116
+
117
+ Example:
118
+ ```
119
+ comment = ProductHunt::Client.new('mytoken').post(3372).comments(order: 'asc').first
120
+
121
+ user_hash = comment["user"] # this will access the partial user details embedded in the response to the #comments call above
122
+ user_hash.class
123
+ # => Hash
124
+ user_hash["name"]
125
+ # => "Andreas Klinger"
126
+
127
+ user_object = comment.user # this will make a separate call to pull the full details of the user who commented
128
+ user_object.class
129
+ # => ProductHunt::User
130
+ user_object["name"]
131
+ # => "Andreas Klinger"
132
+
133
+ post_object = comment.post # likewise for the associated post, this will pull full details of the post on which a comment was made via an additional API call
134
+ post_object.class
135
+ # => ProductHunt::Post
136
+ post_object["name"]
137
+ # => "namevine"
138
+ ```
139
+
140
+ ## Tests
141
+
142
+ There are two ways to run tests:
16
143
 
144
+ 1. `env TOKEN=mytoken bundle exec rake` which stubs out all of the calls to Product Hunt's API to local files.
17
145
 
18
- ### In Progress
146
+ 2. `env TOKEN=mytoken SKIP_CALL_STUBS=true bundle exec rake` which runs tests against live data from the Product Hunt API.
19
147
 
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
148
 
149
+ ## Contributing
22
150
 
23
- ## Examples
151
+ Easy.
24
152
 
25
- For now, see `product_hunt_spec.rb` for examples covering each of the supported endpoints.
153
+ 1. [Fork it](https://github.com/mikejarema/hunting_season/fork)
154
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
155
+ 3. Add new functionality, relevant tests and update the README if applicable
156
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
157
+ 5. Push to the branch (`git push origin my-new-feature`)
158
+ 6. Create a new Pull Request
26
159
 
27
160
 
28
161
  ## Miscellany
29
162
 
30
163
  Legal: see LICENSE
31
164
 
32
- Quick shout out to [Katchphraze](http://on.rdio.com/1zEb5cA) for unintentionally naming this gem 7 years later :headphones:
165
+ The name is inspired by a rapper buddy of mine: [Katchphraze - Huntin' Season](http://on.rdio.com/1zEb5cA) :headphones:
33
166
 
34
167
  Copyright (c) 2014 Mike Jarema
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -1,5 +1,3 @@
1
- # TODO: factor out a base class btw User and Post
2
-
3
1
  module ProductHunt
4
2
  module API
5
3
  include ProductHunt::API::Posts
@@ -10,5 +10,19 @@ module ProductHunt
10
10
  @attributes[key]
11
11
  end
12
12
 
13
+ [:user, :post].each do |method|
14
+ eval <<-GENERATED_METHOD
15
+ def #{method}
16
+ if @client.is_a?(Client) && @attributes['#{method}'].is_a?(Hash) && @attributes['#{method}']['id']
17
+ @client.send('#{method}', @attributes['#{method}']['id'])
18
+ elsif @client.is_a?(Client) && @attributes['#{method}_id']
19
+ @client.send('#{method}', @attributes['#{method}_id'])
20
+ else
21
+ raise NoMethodError.new("undefined method `#{method}' for " + self.inspect)
22
+ end
23
+ end
24
+ GENERATED_METHOD
25
+ end
26
+
13
27
  end
14
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hunting_season
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Jarema
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty