weary 0.1.0 → 0.1.2

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.
data/.gitignore CHANGED
@@ -1,2 +1,2 @@
1
- examples
2
- pkg
1
+ pkg/
2
+ doc/
data/Rakefile CHANGED
@@ -3,17 +3,25 @@ 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
- gemspec.rubyforge_project = "weary"
17
25
  end
18
26
  rescue LoadError
19
27
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
@@ -35,7 +43,7 @@ begin
35
43
 
36
44
  host = "#{config['username']}@rubyforge.org"
37
45
  remote_dir = "/var/www/gforge-projects/weary/"
38
- local_dir = 'rdoc'
46
+ local_dir = 'doc'
39
47
 
40
48
  Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
41
49
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
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
@@ -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\[#{resource.with.collect {|x| ":#{x}"}.join(',')}]\
131
- code << "unnecessary = params.keys - #{with} \n"
132
- code << "unnecessary.each { |x| params.delete(x) } \n"
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 << "options[:body] = params unless params.empty? \n"
132
+ code << %Q{options[:body] = params unless params.empty? \n}
136
133
  else
137
- code << "options[:query] = params unless params.empty? \n"
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
@@ -62,12 +62,12 @@ module Weary
62
62
 
63
63
  def to_hash
64
64
  {@name.to_sym => {:via => @via,
65
- :with => @with,
66
- :requires => @requires,
67
- :authenticates => authenticates?,
68
- :format => @format,
69
- :url => @url},
70
- :no_follow => !follows_redirects?}
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.domain = "http://twitter.com/"
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.format = :xml
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.format = :xml
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 CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{weary}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mark Wunsch"]
9
- s.date = %q{2009-06-08}
9
+ s.date = %q{2009-06-09}
10
10
  s.description = %q{The Weary need REST: a tiny DSL that makes the consumption of RESTful web services simple.}
11
11
  s.email = %q{mark@markwunsch.com}
12
12
  s.extra_rdoc_files = [
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
19
19
  "README.md",
20
20
  "Rakefile",
21
21
  "VERSION",
22
+ "examples/repo.rb",
23
+ "examples/status.rb",
22
24
  "lib/weary.rb",
23
25
  "lib/weary/exceptions.rb",
24
26
  "lib/weary/request.rb",
@@ -28,6 +30,7 @@ Gem::Specification.new do |s|
28
30
  "spec/weary_spec.rb",
29
31
  "weary.gemspec"
30
32
  ]
33
+ s.has_rdoc = true
31
34
  s.homepage = %q{http://github.com/mwunsch/weary}
32
35
  s.rdoc_options = ["--charset=UTF-8"]
33
36
  s.require_paths = ["lib"]
@@ -37,7 +40,8 @@ Gem::Specification.new do |s|
37
40
  s.test_files = [
38
41
  "spec/weary/request_spec.rb",
39
42
  "spec/weary_spec.rb",
40
- "examples/test.rb"
43
+ "examples/repo.rb",
44
+ "examples/status.rb"
41
45
  ]
42
46
 
43
47
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
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-08 00:00:00 -04:00
12
+ date: 2009-06-09 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -28,6 +28,8 @@ files:
28
28
  - README.md
29
29
  - Rakefile
30
30
  - VERSION
31
+ - examples/repo.rb
32
+ - examples/status.rb
31
33
  - lib/weary.rb
32
34
  - lib/weary/exceptions.rb
33
35
  - lib/weary/request.rb
@@ -36,7 +38,7 @@ files:
36
38
  - spec/weary/request_spec.rb
37
39
  - spec/weary_spec.rb
38
40
  - weary.gemspec
39
- has_rdoc: false
41
+ has_rdoc: true
40
42
  homepage: http://github.com/mwunsch/weary
41
43
  post_install_message:
42
44
  rdoc_options:
@@ -65,4 +67,5 @@ summary: A little DSL for consuming RESTful web services
65
67
  test_files:
66
68
  - spec/weary/request_spec.rb
67
69
  - spec/weary_spec.rb
68
- - examples/test.rb
70
+ - examples/repo.rb
71
+ - examples/status.rb
data/examples/test.rb DELETED
@@ -1,4 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'lib', 'weary')
2
- require 'pp'
3
-
4
- r = Weary::Request.new("http://markwunsch.com").perform.search("h1 a")