mwunsch-weary 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/README.md +10 -1
- data/Rakefile +34 -1
- data/VERSION +1 -1
- data/examples/repo.rb +21 -0
- data/examples/status.rb +16 -0
- data/lib/weary.rb +8 -8
- data/lib/weary/resource.rb +6 -6
- data/spec/weary_spec.rb +3 -18
- data/weary.gemspec +56 -0
- metadata +10 -4
data/.gitignore
ADDED
data/README.md
CHANGED
@@ -2,4 +2,13 @@
|
|
2
2
|
|
3
3
|
_The Weary need REST_
|
4
4
|
|
5
|
-
Weary is a tiny
|
5
|
+
Weary is a tiny DSL for making the consumption of RESTful web services simple. It is the little brother to [HTTParty](http://github.com/jnunemaker/httparty/ "JNunemaker's HTTParty"). It provides a thin, gossamer-like layer over the Net/HTTP library.
|
6
|
+
|
7
|
+
The things it do:
|
8
|
+
|
9
|
+
+ Quickly build an interface to your favorite REST API.
|
10
|
+
+ Parse XML and JSON with the [Crack](http://github.com/jnunemaker/crack) library.
|
11
|
+
|
12
|
+
## Requirements
|
13
|
+
|
14
|
+
+ Crack
|
data/Rakefile
CHANGED
@@ -3,22 +3,55 @@ require 'spec/rake/spectask'
|
|
3
3
|
|
4
4
|
task :default => :spec
|
5
5
|
|
6
|
+
require 'rake/rdoctask'
|
7
|
+
Rake::RDocTask.new do |rdoc|
|
8
|
+
rdoc.rdoc_dir = 'doc'
|
9
|
+
rdoc.title = 'weary'
|
10
|
+
rdoc.main = 'README.md'
|
11
|
+
rdoc.rdoc_files.include('README.*', 'lib/**/*.rb', 'LICENSE')
|
12
|
+
rdoc.options << '--inline-source'
|
13
|
+
end
|
14
|
+
|
6
15
|
begin
|
7
16
|
require 'jeweler'
|
8
17
|
Jeweler::Tasks.new do |gemspec|
|
9
18
|
gemspec.name = "weary"
|
19
|
+
gemspec.rubyforge_project = "weary"
|
10
20
|
gemspec.summary = "A little DSL for consuming RESTful web services"
|
11
21
|
gemspec.email = "mark@markwunsch.com"
|
12
22
|
gemspec.homepage = "http://github.com/mwunsch/weary"
|
13
23
|
gemspec.description = "The Weary need REST: a tiny DSL that makes the consumption of RESTful web services simple."
|
14
24
|
gemspec.authors = "Mark Wunsch"
|
15
|
-
gemspec.has_rdoc = false
|
16
25
|
end
|
17
26
|
rescue LoadError
|
18
27
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
19
28
|
end
|
20
29
|
|
30
|
+
begin
|
31
|
+
require 'rake/contrib/sshpublisher'
|
32
|
+
namespace :rubyforge do
|
33
|
+
|
34
|
+
desc "Release gem and RDoc documentation to RubyForge"
|
35
|
+
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
|
36
|
+
|
37
|
+
namespace :release do
|
38
|
+
desc "Publish RDoc to RubyForge."
|
39
|
+
task :docs => [:rdoc] do
|
40
|
+
config = YAML.load(
|
41
|
+
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
42
|
+
)
|
21
43
|
|
44
|
+
host = "#{config['username']}@rubyforge.org"
|
45
|
+
remote_dir = "/var/www/gforge-projects/weary/"
|
46
|
+
local_dir = 'doc'
|
47
|
+
|
48
|
+
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
rescue LoadError
|
53
|
+
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
54
|
+
end
|
22
55
|
|
23
56
|
Spec::Rake::SpecTask.new do |t|
|
24
57
|
t.spec_files = FileList['spec/**/*_spec.rb']
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/examples/repo.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'weary')
|
2
|
+
|
3
|
+
class Repository
|
4
|
+
extend Weary
|
5
|
+
|
6
|
+
@gh_user = "mwunsch"
|
7
|
+
@gh_repo = "weary"
|
8
|
+
|
9
|
+
on_domain "http://github.com/api/v2/"
|
10
|
+
as_format :yaml
|
11
|
+
|
12
|
+
get "show",
|
13
|
+
:url => "<domain><format>/repos/show/#{@gh_user}/#{@gh_repo}"
|
14
|
+
|
15
|
+
get "network",
|
16
|
+
:url => "<domain><format>/repos/show/#{@gh_user}/#{@gh_repo}/network"
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
weary = Repository.new
|
21
|
+
puts weary.show.body
|
data/examples/status.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'weary')
|
2
|
+
|
3
|
+
class Status
|
4
|
+
extend Weary
|
5
|
+
|
6
|
+
on_domain "http://twitter.com/statuses/"
|
7
|
+
|
8
|
+
get "user_timeline",
|
9
|
+
:requires => [:id],
|
10
|
+
:with => [:user_id, :screen_name, :since_id, :max_id, :count, :page]
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
toots = Status.new
|
15
|
+
recent_toot = toots.user_timeline(:id => "markwunsch", :count => 1).parse
|
16
|
+
puts "@" + recent_toot[0]["user"]["screen_name"] + ": " + "\"#{recent_toot[0]['text']}\""
|
data/lib/weary.rb
CHANGED
@@ -38,17 +38,14 @@ module Weary
|
|
38
38
|
raise ArgumentError, 'The domain must be a URL.' if parse_domain.empty?
|
39
39
|
@domain = parse_domain[0]
|
40
40
|
end
|
41
|
-
alias domain= on_domain
|
42
41
|
|
43
42
|
def as_format(format)
|
44
43
|
@default_format = format.to_sym
|
45
44
|
end
|
46
|
-
alias format= as_format
|
47
45
|
|
48
46
|
def construct_url(pattern)
|
49
47
|
@url_pattern = pattern.to_s
|
50
48
|
end
|
51
|
-
alias url= construct_url
|
52
49
|
|
53
50
|
def authenticates_with(username,password)
|
54
51
|
@username = username
|
@@ -127,19 +124,22 @@ module Weary
|
|
127
124
|
end
|
128
125
|
end
|
129
126
|
unless resource.with.nil?
|
130
|
-
with = %Q
|
131
|
-
code <<
|
132
|
-
code <<
|
127
|
+
with = %Q{[#{resource.with.collect {|x| ":#{x}"}.join(',')}]}
|
128
|
+
code << %Q{unnecessary = params.keys - #{with} \n}
|
129
|
+
code << %Q{unnecessary.each { |x| params.delete(x) } \n}
|
133
130
|
end
|
134
131
|
if resource.via == (:post || :put)
|
135
|
-
code <<
|
132
|
+
code << %Q{options[:body] = params unless params.empty? \n}
|
136
133
|
else
|
137
|
-
code <<
|
134
|
+
code << %Q{options[:query] = params unless params.empty? \n}
|
138
135
|
code << %Q{url << "?" + options[:query].to_params unless options[:query].nil? \n}
|
139
136
|
end
|
140
137
|
if resource.authenticates?
|
141
138
|
code << %Q{options[:basic_auth] = {:username => "#{@username}", :password => "#{@password}"} \n}
|
142
139
|
end
|
140
|
+
unless resource.follows_redirects?
|
141
|
+
code << %Q{options[:no_follow] = true \n}
|
142
|
+
end
|
143
143
|
code << %Q{
|
144
144
|
Weary::Request.new(url, :#{resource.via}, options).perform
|
145
145
|
end
|
data/lib/weary/resource.rb
CHANGED
@@ -62,12 +62,12 @@ module Weary
|
|
62
62
|
|
63
63
|
def to_hash
|
64
64
|
{@name.to_sym => {:via => @via,
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
:with => @with,
|
66
|
+
:requires => @requires,
|
67
|
+
:no_follow => !follows_redirects?,
|
68
|
+
:authenticates => authenticates?,
|
69
|
+
:format => @format,
|
70
|
+
:url => @url}}
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
data/spec/weary_spec.rb
CHANGED
@@ -15,11 +15,6 @@ describe Weary do
|
|
15
15
|
@test.domain.should == "http://twitter.com/"
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should also be set by it's alias" do
|
19
|
-
@test.domain = "http://twitter.com/"
|
20
|
-
@test.domain.should == "http://twitter.com/"
|
21
|
-
end
|
22
|
-
|
23
18
|
it 'should raise an exception when a url is not present' do
|
24
19
|
lambda { @test.on_domain("foobar") }.should raise_error
|
25
20
|
end
|
@@ -36,11 +31,6 @@ describe Weary do
|
|
36
31
|
@test.instance_variable_defined?(:@default_format).should == true
|
37
32
|
end
|
38
33
|
|
39
|
-
it "should also be set by it's alias" do
|
40
|
-
@test.format = "xml"
|
41
|
-
@test.instance_variable_defined?(:@default_format).should == true
|
42
|
-
end
|
43
|
-
|
44
34
|
it 'should be a symbol' do
|
45
35
|
@test.as_format("xml")
|
46
36
|
@test.instance_variable_get(:@default_format).class.should == Symbol
|
@@ -53,11 +43,6 @@ describe Weary do
|
|
53
43
|
@test.instance_variable_defined?(:@url_pattern).should == true
|
54
44
|
end
|
55
45
|
|
56
|
-
it "should also be set by it's alias" do
|
57
|
-
@test.url = "<domain><resource>.<format>"
|
58
|
-
@test.instance_variable_defined?(:@url_pattern).should == true
|
59
|
-
end
|
60
|
-
|
61
46
|
it 'should be a string' do
|
62
47
|
@test.construct_url(123)
|
63
48
|
@test.instance_variable_get(:@url_pattern).class.should == String
|
@@ -74,7 +59,7 @@ describe Weary do
|
|
74
59
|
|
75
60
|
describe "resource declaration" do
|
76
61
|
before do
|
77
|
-
@test.
|
62
|
+
@test.on_domain "http://twitter.com/"
|
78
63
|
end
|
79
64
|
|
80
65
|
it "should adds a new resource" do
|
@@ -91,12 +76,12 @@ describe Weary do
|
|
91
76
|
end
|
92
77
|
|
93
78
|
it "should use the declared format, if a specific format is not defined" do
|
94
|
-
@test.
|
79
|
+
@test.as_format :xml
|
95
80
|
@test.declare_resource("resource")[:resource][:format].should == :xml
|
96
81
|
end
|
97
82
|
|
98
83
|
it "should override the default format with it's own format" do
|
99
|
-
@test.
|
84
|
+
@test.as_format :xml
|
100
85
|
@test.declare_resource("resource",{:format => :yaml})[:resource][:format].should == :yaml
|
101
86
|
end
|
102
87
|
|
data/weary.gemspec
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{weary}
|
5
|
+
s.version = "0.1.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Mark Wunsch"]
|
9
|
+
s.date = %q{2009-06-09}
|
10
|
+
s.description = %q{The Weary need REST: a tiny DSL that makes the consumption of RESTful web services simple.}
|
11
|
+
s.email = %q{mark@markwunsch.com}
|
12
|
+
s.extra_rdoc_files = [
|
13
|
+
"LICENSE",
|
14
|
+
"README.md"
|
15
|
+
]
|
16
|
+
s.files = [
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.md",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"examples/repo.rb",
|
23
|
+
"examples/status.rb",
|
24
|
+
"lib/weary.rb",
|
25
|
+
"lib/weary/exceptions.rb",
|
26
|
+
"lib/weary/request.rb",
|
27
|
+
"lib/weary/resource.rb",
|
28
|
+
"lib/weary/response.rb",
|
29
|
+
"spec/weary/request_spec.rb",
|
30
|
+
"spec/weary_spec.rb",
|
31
|
+
"weary.gemspec"
|
32
|
+
]
|
33
|
+
s.has_rdoc = true
|
34
|
+
s.homepage = %q{http://github.com/mwunsch/weary}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubyforge_project = %q{weary}
|
38
|
+
s.rubygems_version = %q{1.3.1}
|
39
|
+
s.summary = %q{A little DSL for consuming RESTful web services}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/weary/request_spec.rb",
|
42
|
+
"spec/weary_spec.rb",
|
43
|
+
"examples/repo.rb",
|
44
|
+
"examples/status.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 2
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
|
+
else
|
53
|
+
end
|
54
|
+
else
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mwunsch-weary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Wunsch
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-09 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -23,10 +23,13 @@ extra_rdoc_files:
|
|
23
23
|
- LICENSE
|
24
24
|
- README.md
|
25
25
|
files:
|
26
|
+
- .gitignore
|
26
27
|
- LICENSE
|
27
28
|
- README.md
|
28
29
|
- Rakefile
|
29
30
|
- VERSION
|
31
|
+
- examples/repo.rb
|
32
|
+
- examples/status.rb
|
30
33
|
- lib/weary.rb
|
31
34
|
- lib/weary/exceptions.rb
|
32
35
|
- lib/weary/request.rb
|
@@ -34,7 +37,8 @@ files:
|
|
34
37
|
- lib/weary/response.rb
|
35
38
|
- spec/weary/request_spec.rb
|
36
39
|
- spec/weary_spec.rb
|
37
|
-
|
40
|
+
- weary.gemspec
|
41
|
+
has_rdoc: true
|
38
42
|
homepage: http://github.com/mwunsch/weary
|
39
43
|
post_install_message:
|
40
44
|
rdoc_options:
|
@@ -55,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
59
|
version:
|
56
60
|
requirements: []
|
57
61
|
|
58
|
-
rubyforge_project:
|
62
|
+
rubyforge_project: weary
|
59
63
|
rubygems_version: 1.2.0
|
60
64
|
signing_key:
|
61
65
|
specification_version: 2
|
@@ -63,3 +67,5 @@ summary: A little DSL for consuming RESTful web services
|
|
63
67
|
test_files:
|
64
68
|
- spec/weary/request_spec.rb
|
65
69
|
- spec/weary_spec.rb
|
70
|
+
- examples/repo.rb
|
71
|
+
- examples/status.rb
|