rubyoverflow 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +4 -0
- data/.rvmrc +47 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +32 -0
- data/RELEASENOTES +2 -0
- data/Rakefile +10 -0
- data/VERSION +1 -0
- data/lib/rubyoverflow.rb +67 -0
- data/lib/rubyoverflow/sites.rb +20 -0
- data/lib/rubyoverflow/users.rb +24 -0
- data/lib/rubyoverflow/version.rb +3 -0
- data/rubyoverflow.gemspec +26 -0
- data/spec/sites_spec.rb +18 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/users_spec.rb +23 -0
- metadata +122 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.9.2-p290@rubyoverflow"
|
8
|
+
|
9
|
+
#
|
10
|
+
# Uncomment following line if you want options to be set only for given project.
|
11
|
+
#
|
12
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
13
|
+
|
14
|
+
#
|
15
|
+
# First we attempt to load the desired environment directly from the environment
|
16
|
+
# file. This is very fast and efficient compared to running through the entire
|
17
|
+
# CLI and selector. If you want feedback on which environment was used then
|
18
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
19
|
+
#
|
20
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
21
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
22
|
+
then
|
23
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
24
|
+
|
25
|
+
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
26
|
+
then
|
27
|
+
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
28
|
+
fi
|
29
|
+
else
|
30
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
31
|
+
if ! rvm --create use "$environment_id"
|
32
|
+
then
|
33
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
34
|
+
exit 1
|
35
|
+
fi
|
36
|
+
fi
|
37
|
+
|
38
|
+
#
|
39
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
40
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
41
|
+
# necessary.
|
42
|
+
#
|
43
|
+
# filename=".gems"
|
44
|
+
# if [[ -s "$filename" ]] ; then
|
45
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
46
|
+
# fi
|
47
|
+
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 phsr
|
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.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= rubyoverflow
|
2
|
+
|
3
|
+
{<img src="https://secure.travis-ci.org/phsr/rubyoverflow.png" />}[http://travis-ci.org/phsr/rubyoverflow]
|
4
|
+
|
5
|
+
rubyoverflow is a library for querying the Stack Overflow API
|
6
|
+
|
7
|
+
== Example
|
8
|
+
|
9
|
+
require 'rubyoverflow'
|
10
|
+
|
11
|
+
c = Rubyoverflow::Client.new
|
12
|
+
result = c.users.fetch(:id => 53587) # By default, this will query StackOverflow.com
|
13
|
+
me = result.users.first # Get the first user out of the results
|
14
|
+
puts me.display_name # => "Dan Seaver"
|
15
|
+
|
16
|
+
|
17
|
+
c = Rubyoverflow::Client.new :host => "api.serverfault.com" # Query ServerFault.com
|
18
|
+
|
19
|
+
== Note on Patches/Pull Requests
|
20
|
+
|
21
|
+
* Fork the project.
|
22
|
+
* Make your feature addition or bug fix.
|
23
|
+
* Add tests for it. This is important so I don't break it in a
|
24
|
+
future version unintentionally.
|
25
|
+
* Commit, do not mess with rakefile, version, or history.
|
26
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
27
|
+
* Send me a pull request. Bonus points for topic branches.
|
28
|
+
|
29
|
+
== Copyright
|
30
|
+
|
31
|
+
Copyright (c) 2011 Dan Seaver. See LICENSE for details.
|
32
|
+
|
data/RELEASENOTES
ADDED
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5
|
data/lib/rubyoverflow.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
path = File.expand_path(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
|
3
|
+
|
4
|
+
require 'httparty'
|
5
|
+
require 'ostruct'
|
6
|
+
|
7
|
+
require 'hashie'
|
8
|
+
require 'json'
|
9
|
+
require 'rubyoverflow/sites'
|
10
|
+
require 'rubyoverflow/users'
|
11
|
+
require "rubyoverflow/version"
|
12
|
+
|
13
|
+
module Rubyoverflow
|
14
|
+
class Client
|
15
|
+
include HTTParty
|
16
|
+
format :plain
|
17
|
+
HOST = 'http://api.stackoverflow.com'
|
18
|
+
VERSION = '1.1'
|
19
|
+
|
20
|
+
attr_accessor :host
|
21
|
+
attr_accessor :api_key
|
22
|
+
|
23
|
+
def initialize(options = OpenStruct.new)
|
24
|
+
if options.kind_of? OpenStruct
|
25
|
+
@host = options.host || HOST
|
26
|
+
@version = options.version || VERSION
|
27
|
+
@api_key = options.api_key if options.api_key
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def request(path, parameters = {})
|
32
|
+
parameters['key'] = @api_key unless @api_key.nil? || @api_key.empty?
|
33
|
+
url = host_path + normalize(path) + query_string(parameters)
|
34
|
+
response = self.class.get url
|
35
|
+
return JSON.parse(response.body), url
|
36
|
+
end
|
37
|
+
|
38
|
+
def host_path
|
39
|
+
normalize(@host) + normalize(@version)
|
40
|
+
end
|
41
|
+
|
42
|
+
class << self
|
43
|
+
def stackauth_client(api_key = '')
|
44
|
+
options = OpenStruct.new
|
45
|
+
options.host = 'http://stackauth.com/'
|
46
|
+
options.api_key = api_key if api_key
|
47
|
+
Client.new options
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def normalize(path)
|
53
|
+
path.end_with?('/') ? path : path+ '/'
|
54
|
+
end
|
55
|
+
|
56
|
+
def query_string(parameters)
|
57
|
+
if !parameters.empty?
|
58
|
+
params = parameters.sort_by { |k, v| k.to_s }
|
59
|
+
pairs = params.map { |key, value| "#{key}=#{value}" }
|
60
|
+
|
61
|
+
'?' + pairs.join('&')
|
62
|
+
else
|
63
|
+
''
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class Sites
|
3
|
+
@client = nil
|
4
|
+
def fetch(params = {})
|
5
|
+
@client ||= Client.stackauth_client
|
6
|
+
|
7
|
+
hash,url = @client.request 'sites', params
|
8
|
+
|
9
|
+
Hashie::Mash.new hash
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Client
|
14
|
+
@sites = nil
|
15
|
+
|
16
|
+
def sites
|
17
|
+
@sites ||= Sites.new
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Rubyoverflow
|
2
|
+
class Users
|
3
|
+
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
def fetch(params = {})
|
9
|
+
ids = params.delete(:id) if params[:id]
|
10
|
+
ids = ids.join(';') if ids and ids.kind_of? Array
|
11
|
+
hash,url = @client.request "users#{"/#{ids}" if ids}", params
|
12
|
+
|
13
|
+
Hashie::Mash.new hash
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Client
|
18
|
+
@users = nil
|
19
|
+
|
20
|
+
def users
|
21
|
+
@users ||= Users.new(self)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rubyoverflow/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rubyoverflow"
|
7
|
+
s.version = Rubyoverflow::VERSION
|
8
|
+
s.authors = ["Dan Seaver"]
|
9
|
+
s.email = ["git@danseaver.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Rubyoverflow is a Ruby wrapper for the Stack Exchange APIs}
|
12
|
+
s.description = %q{Rubyoverflow is a Ruby wrapper for the Stack Exchange APIs}
|
13
|
+
|
14
|
+
s.rubyforge_project = "rubyoverflow"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency('httparty')
|
22
|
+
s.add_dependency('hashie')
|
23
|
+
s.add_dependency('json')
|
24
|
+
s.add_development_dependency('rspec')
|
25
|
+
s.add_development_dependency('rake')
|
26
|
+
end
|
data/spec/sites_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe Sites do
|
4
|
+
before(:each) do
|
5
|
+
@client = Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "retrieves sites" do
|
9
|
+
result = @client.sites.fetch
|
10
|
+
result.should respond_to(:items)
|
11
|
+
result.page.should == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it "retrieves second page of sites" do
|
15
|
+
result = @client.sites.fetch :page => 2
|
16
|
+
result.page.should == 2
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/users_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/spec_helper"
|
2
|
+
|
3
|
+
describe Users do
|
4
|
+
before(:each) do
|
5
|
+
@client = Client.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "retrieves sites" do
|
9
|
+
result = @client.users.fetch
|
10
|
+
result.should respond_to(:users)
|
11
|
+
result.page.should == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it "retrieves phsr" do
|
15
|
+
result = @client.users.fetch(:id => 53587)
|
16
|
+
result.users.first.display_name.should == 'Dan Seaver'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "retrieves multiple users by an array of ids" do
|
20
|
+
result = @client.users.fetch(:id => [53587,22656])
|
21
|
+
result.total.should == 2
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubyoverflow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.5'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Seaver
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-12 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: &2156604660 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2156604660
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: hashie
|
27
|
+
requirement: &2156603920 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2156603920
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: json
|
38
|
+
requirement: &2156602940 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2156602940
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &2156602240 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2156602240
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rake
|
60
|
+
requirement: &2156570520 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2156570520
|
69
|
+
description: Rubyoverflow is a Ruby wrapper for the Stack Exchange APIs
|
70
|
+
email:
|
71
|
+
- git@danseaver.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .document
|
77
|
+
- .gitignore
|
78
|
+
- .rvmrc
|
79
|
+
- .travis.yml
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE
|
83
|
+
- README.rdoc
|
84
|
+
- RELEASENOTES
|
85
|
+
- Rakefile
|
86
|
+
- VERSION
|
87
|
+
- lib/rubyoverflow.rb
|
88
|
+
- lib/rubyoverflow/sites.rb
|
89
|
+
- lib/rubyoverflow/users.rb
|
90
|
+
- lib/rubyoverflow/version.rb
|
91
|
+
- rubyoverflow.gemspec
|
92
|
+
- spec/sites_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
- spec/users_spec.rb
|
95
|
+
homepage: ''
|
96
|
+
licenses: []
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project: rubyoverflow
|
115
|
+
rubygems_version: 1.8.11
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: Rubyoverflow is a Ruby wrapper for the Stack Exchange APIs
|
119
|
+
test_files:
|
120
|
+
- spec/sites_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
- spec/users_spec.rb
|