rlivsey-voorhees 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -22,20 +22,15 @@
22
22
  end
23
23
  end
24
24
 
25
- user = User.get(1)
25
+ users = User.list(:page => 2)
26
+
27
+ user = users[0]
26
28
  user.json_attributes => [:id, :login, :email]
27
29
  user.raw_json => {:id => 1, :login => 'test', :email => 'bob@example.com'}
28
30
  user.login => 'test'
29
- user.login = 'new login'
30
- user.login => 'new login'
31
-
32
31
  user.messages => [Message, Message, Message, ...]
33
-
34
- User.list(:filter => 'xxx') => [User, User, User, ...]
35
- User.list(:blah => false) => raises ParameterRequiredException
36
- etc...
37
32
 
38
- See /examples/ directory for more.
33
+ See [/examples/](examples/) directory for more.
39
34
 
40
35
  ## A bit more in-depth
41
36
 
@@ -83,6 +78,11 @@ This sets up a class method
83
78
 
84
79
  User.list(:page => 3) => [User, User, User, ...]
85
80
 
81
+ By default it assumes you're getting items of the same class, you can override this like so:
82
+
83
+ json_service :list, :path => "/users.json",
84
+ :class => OtherClass
85
+
86
86
  #### json_request
87
87
 
88
88
  This is used in instance methods:
@@ -100,7 +100,7 @@ This is used in instance methods:
100
100
 
101
101
  User.new.friends(:limit => 2) => [User, User]
102
102
 
103
- By default it assumes you're getting items of the same class, you can override this like so:
103
+ Like json_service, by default it assumes you're getting items of the same class, you can override this like so:
104
104
 
105
105
  def messages
106
106
  json_request(Message) do |r|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -20,10 +20,11 @@ module Voorhees
20
20
  end
21
21
 
22
22
  def json_service(name, request_options={})
23
+ klass = request_options.delete(:class) || self
23
24
  (class << self; self; end).instance_eval do
24
25
  define_method name do |*args|
25
26
  params = args[0]
26
- json_request do |r|
27
+ json_request(klass) do |r|
27
28
  r.parameters = params if params.is_a?(Hash)
28
29
  request_options.each do |option, value|
29
30
  r.send("#{option}=", value)
@@ -46,8 +47,8 @@ module Voorhees
46
47
  @json_attributes ||= @raw_json.keys.collect{|x| x.to_sym}
47
48
  end
48
49
 
49
- def json_request
50
- self.class.json_request do |r|
50
+ def json_request(klass=nil)
51
+ self.class.json_request(klass) do |r|
51
52
  yield r
52
53
  end
53
54
  end
data/voorhees.gemspec ADDED
@@ -0,0 +1,65 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{voorhees}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Richard Livsey"]
9
+ s.date = %q{2009-06-21}
10
+ s.email = %q{richard@livsey.org}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.markdown"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.markdown",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "examples/twitter.rb",
23
+ "lib/voorhees.rb",
24
+ "lib/voorhees/config.rb",
25
+ "lib/voorhees/exceptions.rb",
26
+ "lib/voorhees/request.rb",
27
+ "lib/voorhees/resource.rb",
28
+ "lib/voorhees/response.rb",
29
+ "spec/config_spec.rb",
30
+ "spec/fixtures/resources.rb",
31
+ "spec/fixtures/user.json",
32
+ "spec/fixtures/users.json",
33
+ "spec/request_spec.rb",
34
+ "spec/resource_spec.rb",
35
+ "spec/response_spec.rb",
36
+ "spec/spec_helper.rb",
37
+ "spec/voorhees_spec.rb",
38
+ "voorhees.gemspec"
39
+ ]
40
+ s.homepage = %q{http://github.com/rlivsey/voorhees}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.3}
44
+ s.summary = %q{Library to consume and interract with JSON services}
45
+ s.test_files = [
46
+ "spec/config_spec.rb",
47
+ "spec/fixtures/resources.rb",
48
+ "spec/request_spec.rb",
49
+ "spec/resource_spec.rb",
50
+ "spec/response_spec.rb",
51
+ "spec/spec_helper.rb",
52
+ "spec/voorhees_spec.rb",
53
+ "examples/twitter.rb"
54
+ ]
55
+
56
+ if s.respond_to? :specification_version then
57
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
58
+ s.specification_version = 3
59
+
60
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
61
+ else
62
+ end
63
+ else
64
+ end
65
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rlivsey-voorhees
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Livsey
@@ -45,6 +45,7 @@ files:
45
45
  - spec/response_spec.rb
46
46
  - spec/spec_helper.rb
47
47
  - spec/voorhees_spec.rb
48
+ - voorhees.gemspec
48
49
  has_rdoc: false
49
50
  homepage: http://github.com/rlivsey/voorhees
50
51
  post_install_message: