hn_api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +19 -0
- data/LICENSE.txt +20 -0
- data/README.md +18 -0
- data/Rakefile +46 -0
- data/lib/hn/client.rb +27 -0
- data/lib/hn/configuration.rb +28 -0
- data/lib/hn/connection.rb +24 -0
- data/lib/hn/request.rb +16 -0
- data/lib/hn/version.rb +14 -0
- data/lib/hn_api.rb +19 -0
- data/spec/hn_api_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +169 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5025908a7656a4cfda10a23815666e2712251751
|
4
|
+
data.tar.gz: 1586072fdea51f0301be0e27dc840e725a589de4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f91f82695b28dae1492545cbfca6ed5360f306ec357f9a6ce7eaccf0121e0f8c4a9895b1faf84a43cf3137930012446cd074ea10a3248c2cd70f2feb69ceebd
|
7
|
+
data.tar.gz: 2e33ab0387af1851cbfc36f6394e73758821d940366a82ebcea6e4fe4b6379c64b9bc26343228e8032a4e62190774dddaf8a3fb664002ac4419c8eea2e93e7cf
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'faraday', '>= 0.7', '< 0.10'
|
4
|
+
gem 'faraday_middleware', '>= 0.8', '< 0.10'
|
5
|
+
gem 'hashie', '>= 0.4.0'
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem 'rspec', '~> 3.0.0'
|
9
|
+
gem 'rdoc', '~> 3.12'
|
10
|
+
gem 'bundler', '~> 1.0'
|
11
|
+
gem 'jeweler', '~> 1.8.7'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'webmock', '~> 1.19.0'
|
16
|
+
gem 'coveralls', require: false
|
17
|
+
gem 'simplecov', require: false
|
18
|
+
gem 'guard-rspec', require: false
|
19
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Rahul Horé
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# hn_api
|
2
|
+
|
3
|
+
A Ruby wrapper for [the Hacker News API](https://github.com/HackerNews/API). Currently very alpha.
|
4
|
+
|
5
|
+
# Contributing to hn_api
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
# Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2014 Rahul Horé. See LICENSE.txt for
|
18
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
require './lib/hn/version'
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "hn_api"
|
19
|
+
gem.version = HN::Version
|
20
|
+
gem.homepage = "http://github.com/O-I/hn_api"
|
21
|
+
gem.license = "MIT"
|
22
|
+
gem.summary = %Q{Ruby wrapper for the Hacker News API}
|
23
|
+
gem.description = %Q{Ruby client for the Hacker News API}
|
24
|
+
gem.email = "hore.rahul@gmail.com"
|
25
|
+
gem.authors = ["Rahul Horé"]
|
26
|
+
# dependencies defined in Gemfile
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rspec/core'
|
31
|
+
require 'rspec/core/rake_task'
|
32
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
33
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
34
|
+
end
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rdoc/task'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = HN::Version
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "hn_api #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/lib/hn/client.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'request'
|
2
|
+
require_relative 'connection'
|
3
|
+
require_relative 'configuration'
|
4
|
+
|
5
|
+
module HN
|
6
|
+
class Client
|
7
|
+
include HN::Request
|
8
|
+
include HN::Connection
|
9
|
+
include HN::Configuration
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
reset
|
13
|
+
end
|
14
|
+
|
15
|
+
def item(id, options = {})
|
16
|
+
get("item/#{id}.json", options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def user(id, options = {})
|
20
|
+
get("user/#{id}.json", options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def top_stories(options = {})
|
24
|
+
get('topstories.json', options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'version'
|
2
|
+
|
3
|
+
module HN
|
4
|
+
module Configuration
|
5
|
+
|
6
|
+
VALID_CONFIGURATION_KEYS = [:api_version, :base_url, :api_url, :headers]
|
7
|
+
|
8
|
+
attr_accessor *VALID_CONFIGURATION_KEYS
|
9
|
+
|
10
|
+
DEFAULT_VERSION = 'v0'
|
11
|
+
DEFAULT_BASE_URL = 'https://hacker-news.firebaseio.com'
|
12
|
+
DEFAULT_API_URL = "#{DEFAULT_BASE_URL}/#{DEFAULT_VERSION}/"
|
13
|
+
DEFAULT_HEADERS = { accept: 'application/json',
|
14
|
+
user_agent: "hn_api gem #{HN::Version}" }
|
15
|
+
|
16
|
+
def configure
|
17
|
+
yield self
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset
|
21
|
+
self.api_version = DEFAULT_VERSION
|
22
|
+
self.base_url = DEFAULT_BASE_URL
|
23
|
+
self.api_url = DEFAULT_API_URL
|
24
|
+
self.headers = DEFAULT_HEADERS
|
25
|
+
self
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
|
3
|
+
module HN
|
4
|
+
module Connection
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def connection
|
9
|
+
options = {
|
10
|
+
headers: headers,
|
11
|
+
ssl: { verify: false },
|
12
|
+
url: api_url
|
13
|
+
}
|
14
|
+
|
15
|
+
Faraday.new(options) do |connection|
|
16
|
+
connection.use Faraday::Request::UrlEncoded
|
17
|
+
connection.use Faraday::Response::RaiseError
|
18
|
+
connection.use Faraday::Response::Mashify
|
19
|
+
connection.use Faraday::Response::ParseJson
|
20
|
+
connection.adapter(Faraday.default_adapter)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/hn/request.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module HN
|
2
|
+
module Request
|
3
|
+
def get(path, options = {})
|
4
|
+
request(:get, path, options)
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def request(method, path, options)
|
10
|
+
response = connection.send(method) do |request|
|
11
|
+
request.url(path, options)
|
12
|
+
end
|
13
|
+
response.body
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/hn/version.rb
ADDED
data/lib/hn_api.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'hn/client'
|
2
|
+
|
3
|
+
module HN
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def new
|
7
|
+
@client ||= HN::Client.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(method, *args, &block)
|
11
|
+
return super unless new.respond_to?(method)
|
12
|
+
new.send(method, *args, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def respond_to?(method, include_private = false)
|
16
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/hn_api_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'hn_api'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hn_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rahul Horé
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "<"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.10'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.7'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "<"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.10'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.7'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: faraday_middleware
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "<"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.10'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0.8'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "<"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.10'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0.8'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: hashie
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.4.0
|
60
|
+
type: :runtime
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 0.4.0
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rspec
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: 3.0.0
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 3.0.0
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rdoc
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '3.12'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '3.12'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: bundler
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '1.0'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: jeweler
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 1.8.7
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 1.8.7
|
123
|
+
description: Ruby client for the Hacker News API
|
124
|
+
email: hore.rahul@gmail.com
|
125
|
+
executables: []
|
126
|
+
extensions: []
|
127
|
+
extra_rdoc_files:
|
128
|
+
- LICENSE.txt
|
129
|
+
- README.md
|
130
|
+
files:
|
131
|
+
- ".document"
|
132
|
+
- ".rspec"
|
133
|
+
- Gemfile
|
134
|
+
- LICENSE.txt
|
135
|
+
- README.md
|
136
|
+
- Rakefile
|
137
|
+
- lib/hn/client.rb
|
138
|
+
- lib/hn/configuration.rb
|
139
|
+
- lib/hn/connection.rb
|
140
|
+
- lib/hn/request.rb
|
141
|
+
- lib/hn/version.rb
|
142
|
+
- lib/hn_api.rb
|
143
|
+
- spec/hn_api_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
homepage: http://github.com/O-I/hn_api
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.4.1
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: Ruby wrapper for the Hacker News API
|
169
|
+
test_files: []
|