hackernews_api 0.0.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzZkM2I0NmJmOWNjOGY4MzJkZDUyNTdhYzczMjJmM2M4ZjA3YzdkNw==
5
+ data.tar.gz: !binary |-
6
+ ODE1ZDM4ODMxYzY2MGIwOGEzM2VhYzEwMmU5N2YzZjI4MDQ0NmFlYw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YmM2ZmMxZmRmOGM3NjU1M2Q3M2JkMzk2ZDM1MTYzM2NjOWIyYjcwZGM3Nzdh
10
+ ZWJiOThiMjE1NzlmYTljZjU4Zjk3NTA1NmYxZmU2NzUwOWY5ODQyMjdkOWVi
11
+ NDQ3OTBkMmJiYzMzYWJmODc0NjNhYzcxYmM3YzljYmJkZTgzZDY=
12
+ data.tar.gz: !binary |-
13
+ YzRkMzc0YTJjMDZhMTE2ZDgyOGQ0YzhlNTM3N2Y3Mzc4OGY3ZGUzM2U0ZDEz
14
+ NWQ2ZjlkNzk2OGIzMDAwNjE0OGFkNWVmYjAzZTY1ZjFjMjBmNjc1YTJiMjU1
15
+ MzY1ODI1NGVlNTZiZTZmYjZkN2UxYzQ5NTFlN2FjNzc3ZTBmODY=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hackernews_api.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
7
+ gem 'vcr'
8
+ gem 'webmock'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ile Eftimov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # HackernewsApi
2
+
3
+ This is a tiny gem that wraps around HN's API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hackernews_api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hackernews_api
18
+
19
+ ## Usage
20
+
21
+ Fetching users by id:
22
+ ```User.fetch(123)```
23
+
24
+ Fetching stories:
25
+ ```Story.fetch(123)```
26
+
27
+ Fetching comment:
28
+ ```Comment.fetch(123)```
29
+
30
+ Fetching poll:
31
+ ```Poll.fetch(123)```
32
+
33
+ All of the fetch actions return adequate entities based on the fetch.
34
+ For example, ```Story.fetch(<some-id-here>)``` will return a ```Story``` object.
35
+
36
+ ## Versioning
37
+ The gem version will **always** follow the API version. Right now, while the API is v0, the gem will have a version of 0.x.x.
38
+ When YC update the API, the new gem will be released under the same version.
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it ( http://github.com/fteem/hackernews_api/fork )
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hackernews_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hackernews_api"
8
+ spec.version = HackernewsApi::VERSION
9
+ spec.authors = ["Ile Eftimov"]
10
+ spec.email = ["ileeftimov@gmail.com"]
11
+ spec.summary = %q{HackerNews API gem}
12
+ spec.description = %q{Easily fetch data from HN's API.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'rest-client', "~> 1.7"
22
+ spec.add_development_dependency "bundler", "~> 1.5"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,10 @@
1
+ require 'json'
2
+
3
+ module HackernewsApi
4
+ class Client
5
+ def self.fetch(entity_type, id)
6
+ raw_json = RestClient.get("#{HackernewsApi::API_URL}/#{HackernewsApi::API_VERSION}/#{entity_type.to_s}/#{id}.json?print=pretty")
7
+ JSON.parse(raw_json)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module HackernewsApi
2
+ class Comment
3
+ def self.fetch id
4
+ json = Client.fetch(:item, id)
5
+ new(json)
6
+ end
7
+
8
+ attr_reader :id, :by, :kids, :time, :type, :parent, :text
9
+
10
+ def initialize json
11
+ @id = json['id']
12
+ @by = json['by']
13
+ @kids = json['kids']
14
+ @time = DateTime.strptime(json['time'].to_s, '%s')
15
+ @type = json['type']
16
+ @parent = json['parent']
17
+ @text = json['text']
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ module HackernewsApi
2
+ class Poll
3
+ def self.fetch id
4
+ json = Client.fetch(:item, id)
5
+ new(json)
6
+ end
7
+
8
+ attr_reader :id, :by, :kids, :score, :time, :title, :type, :text
9
+
10
+ def initialize json
11
+ @id = json['id']
12
+ @by = json['by']
13
+ @kids = json['kids']
14
+ @score = json['score']
15
+ @time = DateTime.strptime(json['time'].to_s, '%s')
16
+ @title = json['title']
17
+ @type = json['type']
18
+ @text = json['text']
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module HackernewsApi
2
+ class PollOpt
3
+ def self.fetch id
4
+ json = Client.fetch(:item, id)
5
+ new(json)
6
+ end
7
+
8
+ attr_reader :id, :by, :parent, :score, :time, :type, :text
9
+
10
+ def initialize json
11
+ @id = json['id']
12
+ @by = json['by']
13
+ @time = DateTime.strptime(json['time'].to_s, '%s')
14
+ @type = json['type']
15
+ @parent = json['parent']
16
+ @text = json['text']
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module HackernewsApi
2
+ class Story
3
+ def self.fetch id
4
+ json = Client.fetch(:item, id)
5
+ new(json)
6
+ end
7
+
8
+ attr_reader :id, :by, :kids, :score, :time, :title, :type, :url
9
+
10
+ def initialize json
11
+ @id = json['id']
12
+ @by = json['by']
13
+ @kids = json['kids']
14
+ @score = json['score']
15
+ @time = DateTime.strptime(json['time'].to_s, '%s')
16
+ @title = json['title']
17
+ @type = json['type']
18
+ @url = json['url']
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ module HackernewsApi
2
+ class User
3
+ def self.fetch id
4
+ new(Client.fetch(:user, id))
5
+ end
6
+
7
+ attr_reader :id, :about, :created, :delay, :karma, :submitted
8
+
9
+ def initialize json
10
+ @id = json['id']
11
+ @aobut = json['about']
12
+ @create = json['created']
13
+ @delay = json['delay']
14
+ @karma = json['karma']
15
+ @submitted = json['submitted']
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module HackernewsApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,14 @@
1
+ require "hackernews_api/version"
2
+ require 'rest_client'
3
+
4
+ module HackernewsApi
5
+ API_URL = "https://hacker-news.firebaseio.com"
6
+ API_VERSION = "v0"
7
+
8
+ autoload :Client, 'hackernews_api/client'
9
+ autoload :Story, 'hackernews_api/story'
10
+ autoload :Comment, 'hackernews_api/comment'
11
+ autoload :Poll, 'hackernews_api/poll'
12
+ autoload :PollOpt, 'hackernews_api/poll_opt'
13
+ autoload :User, 'hackernews_api/user'
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe HackernewsApi::Client do
4
+
5
+ it 'fetches json from HN API' do
6
+ VCR.use_cassette('user') do
7
+ json = described_class.fetch(:user, 'fteem')
8
+ expect(json['id']).to eq 'fteem'
9
+ end
10
+ end
11
+
12
+ end
13
+
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe HackernewsApi::Comment do
4
+ let(:comment) do
5
+ VCR.use_cassette('comment') do
6
+ described_class.fetch 2921983
7
+ end
8
+ end
9
+
10
+ it '#id' do
11
+ expect(comment.id).to eq 2921983
12
+ end
13
+
14
+ it '#by' do
15
+ expect(comment.by).to eq "norvig"
16
+ end
17
+
18
+ it '#kids' do
19
+ expect(comment.kids).to include 2922709
20
+ end
21
+
22
+ it '#parent' do
23
+ expect(comment.parent).to eq 2921506
24
+ end
25
+
26
+ it '#text' do
27
+ expect(comment.text).to eq "Aw shucks, guys ... you make me blush with your compliments.<p>Tell you what, Ill make a deal: I'll keep writing if you keep reading. K?"
28
+ end
29
+
30
+ it '#time' do
31
+ expect(comment.time.to_s).to eq "2011-08-24T18:38:47+00:00"
32
+ end
33
+ it '#type' do
34
+ expect(comment.type).to eq "comment"
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://hacker-news.firebaseio.com/v0/item/2921983.json?print=pretty
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Length:
22
+ - '336'
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Cache-Control:
26
+ - no-cache
27
+ body:
28
+ encoding: US-ASCII
29
+ string: ! "{\n \"by\" : \"norvig\",\n \"id\" : 2921983,\n \"kids\" : [ 2922097,
30
+ 2922429, 2924562, 2922709, 2922573, 2922140, 2922141 ],\n \"parent\" : 2921506,\n
31
+ \ \"text\" : \"Aw shucks, guys ... you make me blush with your compliments.<p>Tell
32
+ you what, Ill make a deal: I'll keep writing if you keep reading. K?\",\n
33
+ \ \"time\" : 1314211127,\n \"type\" : \"comment\"\n}\n"
34
+ http_version:
35
+ recorded_at: Wed, 08 Oct 2014 23:40:22 GMT
36
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://hacker-news.firebaseio.com/v0/item/126809.json?print=pretty
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Length:
22
+ - '445'
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Cache-Control:
26
+ - no-cache
27
+ body:
28
+ encoding: US-ASCII
29
+ string: ! "{\n \"by\" : \"pg\",\n \"id\" : 126809,\n \"kids\" : [ 126822,
30
+ 126823, 126993, 126824, 126934, 127411, 126888, 127681, 126818, 126816, 126854,
31
+ 127095, 126861, 127313, 127299, 126859, 126852, 126882, 126832, 127072, 127217,
32
+ 126889, 127535, 126917, 126875 ],\n \"parts\" : [ 126810, 126811, 126812
33
+ ],\n \"score\" : 46,\n \"text\" : \"\",\n \"time\" : 1204403652,\n \"title\"
34
+ : \"Poll: What would happen if News.YC had explicit support for polls?\",\n
35
+ \ \"type\" : \"poll\"\n}\n"
36
+ http_version:
37
+ recorded_at: Wed, 08 Oct 2014 23:40:23 GMT
38
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,34 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://hacker-news.firebaseio.com/v0/item/160705.json?print=pretty
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Length:
22
+ - '197'
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Cache-Control:
26
+ - no-cache
27
+ body:
28
+ encoding: US-ASCII
29
+ string: ! "{\n \"by\" : \"pg\",\n \"id\" : 160705,\n \"parent\" : 160704,\n
30
+ \ \"score\" : 335,\n \"text\" : \"Yes, ban them; I'm tired of seeing Valleywag
31
+ stories on News.YC.\",\n \"time\" : 1207886576,\n \"type\" : \"pollopt\"\n}\n"
32
+ http_version:
33
+ recorded_at: Wed, 08 Oct 2014 23:47:14 GMT
34
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://hacker-news.firebaseio.com/v0/item/8863.json?print=pretty
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Length:
22
+ - '434'
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Cache-Control:
26
+ - no-cache
27
+ body:
28
+ encoding: US-ASCII
29
+ string: ! "{\n \"by\" : \"dhouston\",\n \"id\" : 8863,\n \"kids\" : [ 8952,
30
+ 9224, 8917, 8884, 8887, 8943, 8869, 8958, 9005, 9671, 8940, 9067, 8908, 9055,
31
+ 8865, 8881, 8872, 8873, 8955, 10403, 8903, 8928, 9125, 8998, 8901, 8902, 8907,
32
+ 8894, 8878, 8870, 8980, 8934, 8876 ],\n \"score\" : 111,\n \"time\" : 1175714200,\n
33
+ \ \"title\" : \"My YC app: Dropbox - Throw away your USB drive\",\n \"type\"
34
+ : \"story\",\n \"url\" : \"http://www.getdropbox.com/u/2/screencast.html\"\n}\n"
35
+ http_version:
36
+ recorded_at: Wed, 08 Oct 2014 23:40:24 GMT
37
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,34 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://hacker-news.firebaseio.com/v0/user/fteem.json?print=pretty
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Length:
22
+ - '177'
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Cache-Control:
26
+ - no-cache
27
+ body:
28
+ encoding: US-ASCII
29
+ string: ! "{\n \"about\" : \"\",\n \"created\" : 1350511163,\n \"delay\"
30
+ : 0,\n \"id\" : \"fteem\",\n \"karma\" : 69,\n \"submitted\" : [ 7108294,
31
+ 6521410, 6465841, 6463575, 5256248, 5188029, 5181227 ]\n}\n"
32
+ http_version:
33
+ recorded_at: Wed, 08 Oct 2014 23:54:17 GMT
34
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe HackernewsApi::PollOpt do
4
+ let(:poll_part) do
5
+ VCR.use_cassette('poll_part') do
6
+ described_class.fetch 160705
7
+ end
8
+ end
9
+
10
+ it '#id' do
11
+ expect(poll_part.id).to eq 160705
12
+ end
13
+
14
+ it '#by' do
15
+ expect(poll_part.by).to eq "pg"
16
+ end
17
+
18
+ it '#parent' do
19
+ expect(poll_part.parent).to eq 160704
20
+ end
21
+
22
+ it '#text' do
23
+ expect(poll_part.text).to eq "Yes, ban them; I'm tired of seeing Valleywag stories on News.YC."
24
+ end
25
+
26
+ it '#time' do
27
+ expect(poll_part.time.to_s).to eq "2008-04-11T04:02:56+00:00"
28
+ end
29
+
30
+ it '#type' do
31
+ expect(poll_part.type).to eq "pollopt"
32
+ end
33
+ end
data/spec/poll_spec.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe HackernewsApi::Poll do
4
+ let(:poll) do
5
+ VCR.use_cassette('poll') do
6
+ described_class.fetch 126809
7
+ end
8
+ end
9
+
10
+ it '#id' do
11
+ expect(poll.id).to eq 126809
12
+ end
13
+
14
+ it '#by' do
15
+ expect(poll.by).to eq "pg"
16
+ end
17
+
18
+ it '#kids' do
19
+ expect(poll.kids).to include 126824
20
+ end
21
+
22
+ it '#score' do
23
+ expect(poll.score).to eq 46
24
+ end
25
+
26
+ it '#text' do
27
+ expect(poll.text).to eq ""
28
+ end
29
+
30
+ it '#time' do
31
+ expect(poll.time.to_s).to eq "2008-03-01T20:34:12+00:00"
32
+ end
33
+
34
+ it '#type' do
35
+ expect(poll.type).to eq "poll"
36
+ end
37
+
38
+ it "#title" do
39
+ expect(poll.title).to eq "Poll: What would happen if News.YC had explicit support for polls?"
40
+ end
41
+ end
@@ -0,0 +1,97 @@
1
+ require './lib/hackernews_api'
2
+ require 'vcr'
3
+
4
+ VCR.configure do |c|
5
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
6
+ c.hook_into :webmock # or :fakeweb
7
+ end
8
+
9
+ # This file was generated by the `rspec --init` command. Conventionally, all
10
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
11
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
12
+ # file to always be loaded, without a need to explicitly require it in any files.
13
+ #
14
+ # Given that it is always loaded, you are encouraged to keep this file as
15
+ # light-weight as possible. Requiring heavyweight dependencies from this file
16
+ # will add to the boot time of your test suite on EVERY test run, even for an
17
+ # individual file that may not need all of that loaded. Instead, consider making
18
+ # a separate helper file that requires the additional dependencies and performs
19
+ # the additional setup, and require it from the spec files that actually need it.
20
+ #
21
+ # The `.rspec` file also contains a few flags that are not defaults but that
22
+ # users commonly want.
23
+ #
24
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
25
+ RSpec.configure do |config|
26
+ # rspec-expectations config goes here. You can use an alternate
27
+ # assertion/expectation library such as wrong or the stdlib/minitest
28
+ # assertions if you prefer.
29
+ config.expect_with :rspec do |expectations|
30
+ # This option will default to `true` in RSpec 4. It makes the `description`
31
+ # and `failure_message` of custom matchers include text for helper methods
32
+ # defined using `chain`, e.g.:
33
+ # be_bigger_than(2).and_smaller_than(4).description
34
+ # # => "be bigger than 2 and smaller than 4"
35
+ # ...rather than:
36
+ # # => "be bigger than 2"
37
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
38
+ end
39
+
40
+ # rspec-mocks config goes here. You can use an alternate test double
41
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
42
+ config.mock_with :rspec do |mocks|
43
+ # Prevents you from mocking or stubbing a method that does not exist on
44
+ # a real object. This is generally recommended, and will default to
45
+ # `true` in RSpec 4.
46
+ mocks.verify_partial_doubles = true
47
+ end
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ =begin
52
+ # These two settings work together to allow you to limit a spec run
53
+ # to individual examples or groups you care about by tagging them with
54
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
55
+ # get run.
56
+ config.filter_run :focus
57
+ config.run_all_when_everything_filtered = true
58
+
59
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
60
+ # For more details, see:
61
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
63
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
64
+ config.disable_monkey_patching!
65
+
66
+ # This setting enables warnings. It's recommended, but in some cases may
67
+ # be too noisy due to issues in dependencies.
68
+ config.warnings = true
69
+
70
+ # Many RSpec users commonly either run the entire suite or an individual
71
+ # file, and it's useful to allow more verbose output when running an
72
+ # individual spec file.
73
+ if config.files_to_run.one?
74
+ # Use the documentation formatter for detailed output,
75
+ # unless a formatter has already been configured
76
+ # (e.g. via a command-line flag).
77
+ config.default_formatter = 'doc'
78
+ end
79
+
80
+ # Print the 10 slowest examples and example groups at the
81
+ # end of the spec run, to help surface which specs are running
82
+ # particularly slow.
83
+ config.profile_examples = 10
84
+
85
+ # Run specs in random order to surface order dependencies. If you find an
86
+ # order dependency and want to debug it, you can fix the order by providing
87
+ # the seed, which is printed after each run.
88
+ # --seed 1234
89
+ config.order = :random
90
+
91
+ # Seed global randomization in this process using the `--seed` CLI option.
92
+ # Setting this allows you to use `--seed` to deterministically reproduce
93
+ # test failures related to randomization by passing the same `--seed` value
94
+ # as the one that triggered the failure.
95
+ Kernel.srand config.seed
96
+ =end
97
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe HackernewsApi::Story do
4
+ let(:story) do
5
+ VCR.use_cassette('story') do
6
+ described_class.fetch 8863
7
+ end
8
+ end
9
+
10
+ it '#id' do
11
+ expect(story.id).to eq 8863
12
+ end
13
+
14
+ it '#by' do
15
+ expect(story.by).to eq "dhouston"
16
+ end
17
+
18
+ it '#kids' do
19
+ expect(story.kids).to include 8952
20
+ end
21
+
22
+ it '#score' do
23
+ expect(story.score).to eq 111
24
+ end
25
+
26
+ it '#time' do
27
+ expect(story.time.to_s).to eq "2007-04-04T19:16:40+00:00"
28
+ end
29
+
30
+ it '#title' do
31
+ expect(story.title).to eq "My YC app: Dropbox - Throw away your USB drive"
32
+ end
33
+
34
+ it '#type' do
35
+ expect(story.type).to eq "story"
36
+ end
37
+
38
+ it '#url' do
39
+ expect(story.url).to eq "http://www.getdropbox.com/u/2/screencast.html"
40
+ end
41
+ end
data/spec/user_spec.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe HackernewsApi::User do
4
+ let(:user) do
5
+ VCR.use_cassette('user') do
6
+ described_class.fetch('fteem')
7
+ end
8
+ end
9
+
10
+ it '#id' do
11
+ expect(user.id).to eq "fteem"
12
+ end
13
+
14
+ it '#about' do
15
+ expect(user.about).to eq nil
16
+ end
17
+
18
+ it '#created' do
19
+ expect(user.created.to_s).to eq ''
20
+ end
21
+
22
+ it '#delay' do
23
+ expect(user.delay).to eq 0
24
+ end
25
+
26
+ it '#karma' do
27
+ expect(user.karma).to eq 69
28
+ end
29
+
30
+ it '#submitted' do
31
+ expect(user.submitted).to eq [7108294, 6521410, 6465841, 6463575, 5256248, 5188029, 5181227]
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hackernews_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ile Eftimov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Easily fetch data from HN's API.
56
+ email:
57
+ - ileeftimov@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - hackernews_api.gemspec
69
+ - lib/hackernews_api.rb
70
+ - lib/hackernews_api/client.rb
71
+ - lib/hackernews_api/comment.rb
72
+ - lib/hackernews_api/poll.rb
73
+ - lib/hackernews_api/poll_opt.rb
74
+ - lib/hackernews_api/story.rb
75
+ - lib/hackernews_api/user.rb
76
+ - lib/hackernews_api/version.rb
77
+ - spec/client_spec.rb
78
+ - spec/comment_spec.rb
79
+ - spec/fixtures/vcr_cassettes/comment.yml
80
+ - spec/fixtures/vcr_cassettes/poll.yml
81
+ - spec/fixtures/vcr_cassettes/poll_part.yml
82
+ - spec/fixtures/vcr_cassettes/story.yml
83
+ - spec/fixtures/vcr_cassettes/user.yml
84
+ - spec/poll_opt_spec.rb
85
+ - spec/poll_spec.rb
86
+ - spec/spec_helper.rb
87
+ - spec/story_spec.rb
88
+ - spec/user_spec.rb
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.4.1
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: HackerNews API gem
113
+ test_files:
114
+ - spec/client_spec.rb
115
+ - spec/comment_spec.rb
116
+ - spec/fixtures/vcr_cassettes/comment.yml
117
+ - spec/fixtures/vcr_cassettes/poll.yml
118
+ - spec/fixtures/vcr_cassettes/poll_part.yml
119
+ - spec/fixtures/vcr_cassettes/story.yml
120
+ - spec/fixtures/vcr_cassettes/user.yml
121
+ - spec/poll_opt_spec.rb
122
+ - spec/poll_spec.rb
123
+ - spec/spec_helper.rb
124
+ - spec/story_spec.rb
125
+ - spec/user_spec.rb
126
+ has_rdoc: