rlivsey-voorhees 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -30,7 +30,7 @@
30
30
  user.login => 'test'
31
31
  user.messages => [Message, Message, Message, ...]
32
32
 
33
- See [/examples/](examples/) directory for more.
33
+ See [/examples/](master/examples/) directory for more.
34
34
 
35
35
  ## A bit more in-depth
36
36
 
@@ -41,27 +41,33 @@ These can all be overridden on individual requests/services
41
41
 
42
42
  Voorhees::Config.setup do |c|
43
43
  c[:base_uri] = "http://api.example.com/json"
44
- c[:required] = [:something]
45
44
  c[:defaults] = {:api_version => 2}
46
45
  c[:timeout] = 10
47
46
  c[:retries] = 3
48
47
  end
49
48
 
50
- #### System options
49
+ #### Global options
51
50
 
52
51
  * logger: set a logger to use for debug messages, defaults to Logger.new(STDOUT) or RAILS_DEFAULT_LOGGER if it's defined
53
52
 
54
- #### Request options
53
+ #### Request global options
54
+
55
+ These can be set in the global config and overridden on individual services/requests
55
56
 
56
57
  * base_uri: Prepend all paths with this, usually the domain of the service
57
58
  * defaults: A hash of default parameters
58
- * hierarchy: Define the class hierarchy for nested data - see below for info
59
59
  * http_method: The Net::HTTP method to use. One of Net::HTTP::Get (default), Net::HTTP::Post, Net::HTTP::Put or Net::HTTP::Delete
60
+ * retries: Number of times to retry if it fails to load data from the service
61
+ * timeout: Number of seconds to wait for the service to send data
62
+
63
+ #### Request specific options
64
+
65
+ These cannot be globally set and can only be defined on individual services/requests
66
+
67
+ * hierarchy: Define the class hierarchy for nested data - see below for info
60
68
  * parameters: Hash of data to send along with the request, overrides any defaults
61
69
  * path: Path to the service. Can be relative if you have a base_uri set.
62
70
  * required: Array of required parameters. Raises a Voorhees::ParameterMissingError if a required parameter is not set.
63
- * retries: Number of times to retry if it fails to load data from the service
64
- * timeout: Number of seconds to wait for the service to send data
65
71
 
66
72
  ### Services and Requests
67
73
 
@@ -104,8 +110,8 @@ Like json_service, by default it assumes you're getting items of the same class,
104
110
 
105
111
  def messages
106
112
  json_request(Message) do |r|
107
- r.path => "/messages.json"
108
- r.parameters => {:user_id => self.id}
113
+ r.path = "/messages.json"
114
+ r.parameters = {:user_id => self.id}
109
115
  end
110
116
  end
111
117
 
@@ -120,8 +126,8 @@ If you like you can use this yourself directly.
120
126
  This sets up a request identical to the json_request messages example above:
121
127
 
122
128
  request = Voorhees::Request.new(Message)
123
- request.path = "/messages.json"
124
- request.parameters => {:user_id => self.id}
129
+ request.path = "/messages.json"
130
+ request.parameters = {:user_id => self.id}
125
131
 
126
132
  To perform the HTTP request (returning a Voorhees::Response object):
127
133
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.3
@@ -29,8 +29,12 @@ module Voorhees
29
29
  @base_uri || Voorhees::Config[:base_uri]
30
30
  end
31
31
 
32
+ def defaults
33
+ @defaults || Voorhees::Config[:defaults]
34
+ end
35
+
32
36
  def parameters
33
- (@defaults || {}).merge(@parameters || {})
37
+ (defaults || {}).merge(@parameters || {})
34
38
  end
35
39
 
36
40
  def timeout
@@ -114,7 +118,6 @@ module Voorhees
114
118
 
115
119
  def parse_response(response)
116
120
  Voorhees::Response.new(JSON.parse(response.body), @caller_class, @hierarchy)
117
-
118
121
  rescue JSON::ParserError
119
122
  raise Voorhees::ParseError
120
123
  end
@@ -59,15 +59,12 @@ module Voorhees
59
59
  if json_attributes.include?(method_name)
60
60
  value = value_from_json(method_name)
61
61
  build_methods(method_name, value)
62
- return value
63
- end
64
-
65
- if method_name.to_s =~ /(.+)=$/ && json_attributes.include?($1.to_sym)
62
+ value
63
+ elsif method_name.to_s =~ /(.+)=$/ && json_attributes.include?($1.to_sym)
66
64
  build_methods($1, args[1])
67
- return
65
+ else
66
+ super
68
67
  end
69
-
70
- super
71
68
  end
72
69
 
73
70
  private
@@ -88,9 +85,9 @@ module Voorhees
88
85
  end
89
86
 
90
87
  if item.is_a?(Array)
91
- return build_collection_from_json(method_name, item, klass, sub_hierarchy)
88
+ build_collection_from_json(method_name, item, klass, sub_hierarchy)
92
89
  else
93
- return build_item(item, klass, sub_hierarchy)
90
+ build_item(item, klass, sub_hierarchy)
94
91
  end
95
92
  end
96
93
 
data/voorhees.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{voorhees}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Richard Livsey"]
@@ -13,8 +13,7 @@ Gem::Specification.new do |s|
13
13
  "README.markdown"
14
14
  ]
15
15
  s.files = [
16
- ".document",
17
- ".gitignore",
16
+ ".gitignore",
18
17
  "LICENSE",
19
18
  "README.markdown",
20
19
  "Rakefile",
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.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Livsey
@@ -23,7 +23,6 @@ extra_rdoc_files:
23
23
  - LICENSE
24
24
  - README.markdown
25
25
  files:
26
- - .document
27
26
  - .gitignore
28
27
  - LICENSE
29
28
  - README.markdown
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE