swivel 0.0.146 → 0.0.149
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -1
- data/Rakefile +1 -1
- data/lib/swivel.rb +1 -1
- data/lib/swivel2/benchmarking.rb +1 -0
- data/lib/swivel2/config.rb +45 -0
- data/lib/swivel2/connection.rb +89 -0
- data/lib/swivel2/formats.rb +11 -0
- data/lib/swivel2/logging.rb +1 -0
- data/lib/swivel2/performance.rb +21 -0
- data/lib/swivel2/response.rb +5 -0
- data/lib/swivel2/swivelrc.default +5 -0
- data/vendor/activeresource-2.0.2-/CHANGELOG +223 -0
- data/vendor/activeresource-2.0.2-/README +165 -0
- data/vendor/activeresource-2.0.2-/Rakefile +133 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource.rb +47 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/base.rb +872 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/connection.rb +172 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/custom_methods.rb +105 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/formats.rb +14 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/formats/json_format.rb +23 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/formats/xml_format.rb +34 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/http_mock.rb +147 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/validations.rb +288 -0
- data/vendor/activeresource-2.0.2-/lib/active_resource/version.rb +9 -0
- data/vendor/activeresource-2.0.2-/lib/activeresource.rb +1 -0
- data/vendor/activeresource-2.0.2-/test/abstract_unit.rb +10 -0
- data/vendor/activeresource-2.0.2-/test/authorization_test.rb +82 -0
- data/vendor/activeresource-2.0.2-/test/base/custom_methods_test.rb +96 -0
- data/vendor/activeresource-2.0.2-/test/base/equality_test.rb +43 -0
- data/vendor/activeresource-2.0.2-/test/base/load_test.rb +111 -0
- data/vendor/activeresource-2.0.2-/test/base_errors_test.rb +48 -0
- data/vendor/activeresource-2.0.2-/test/base_test.rb +454 -0
- data/vendor/activeresource-2.0.2-/test/connection_test.rb +170 -0
- data/vendor/activeresource-2.0.2-/test/fixtures/beast.rb +14 -0
- data/vendor/activeresource-2.0.2-/test/fixtures/person.rb +3 -0
- data/vendor/activeresource-2.0.2-/test/fixtures/street_address.rb +4 -0
- data/vendor/activeresource-2.0.2-/test/format_test.rb +42 -0
- data/vendor/activeresource-2.0.2-/test/setter_trap.rb +27 -0
- data/vendor/activesupport-2.0.2-/CHANGELOG +986 -0
- data/vendor/activesupport-2.0.2-/README +43 -0
- data/vendor/activesupport-2.0.2-/lib/active_support.rb +49 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/basic_object.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/buffered_logger.rb +107 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/clean_logger.rb +127 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext.rb +4 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/access.rb +28 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/conversions.rb +94 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/extract_options.rb +19 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/grouping.rb +68 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/array/random_access.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/bigdecimal.rb +2 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/bigdecimal/conversions.rb +6 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/blank.rb +50 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/cgi.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class.rb +4 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/attribute_accessors.rb +48 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/delegating_attributes.rb +40 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/inheritable_attributes.rb +140 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/class/removal.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date.rb +10 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/behavior.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/calculations.rb +188 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date/conversions.rb +98 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time.rb +10 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time/calculations.rb +77 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/date_time/conversions.rb +74 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/duplicable.rb +37 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/enumerable.rb +63 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/exception.rb +33 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/file.rb +21 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/float.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/float/rounding.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/conversions.rb +242 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/diff.rb +19 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/except.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/indifferent_access.rb +102 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/keys.rb +54 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/reverse_merge.rb +25 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/hash/slice.rb +28 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer.rb +7 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer/even_odd.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/integer/inflections.rb +21 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/daemonizing.rb +15 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/debugger.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/reporting.rb +51 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/kernel/requires.rb +24 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/load_error.rb +38 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/logger.rb +16 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module.rb +8 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/aliasing.rb +70 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attr_accessor_with_default.rb +31 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attr_internal.rb +31 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/attribute_accessors.rb +48 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/delegation.rb +62 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/inclusion.rb +11 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/introspection.rb +35 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/module/loading.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/name_error.rb +17 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric.rb +7 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric/bytes.rb +44 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/numeric/time.rb +91 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object.rb +4 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/conversions.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/extending.rb +58 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/instance_variables.rb +22 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/object/misc.rb +59 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/pathname.rb +7 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/pathname/clean_within.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/proc.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range.rb +11 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/blockless_step.rb +22 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/conversions.rb +23 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/include_range.rb +22 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/range/overlaps.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string.rb +23 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/access.rb +58 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/conversions.rb +28 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/inflections.rb +153 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/iterators.rb +17 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/starts_ends_with.rb +27 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/unicode.rb +42 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/string/xchar.rb +11 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/symbol.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/test.rb +1 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/test/unit/assertions.rb +62 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time.rb +19 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/behavior.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/calculations.rb +224 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/core_ext/time/conversions.rb +94 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/dependencies.rb +540 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/deprecation.rb +204 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/duration.rb +96 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/inflections.rb +53 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/inflector.rb +282 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json.rb +31 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/decoding.rb +60 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/date.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/date_time.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/enumerable.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/false_class.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/hash.rb +50 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/nil_class.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/numeric.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/object.rb +6 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/regexp.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/string.rb +30 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/symbol.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/time.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoders/true_class.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/encoding.rb +38 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/json/variable.rb +10 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte.rb +9 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/chars.rb +141 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/generators/generate_tables.rb +149 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/passthru_handler.rb +9 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/utf8_handler.rb +564 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/multibyte/handlers/utf8_handler_proc.rb +43 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/option_merger.rb +25 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/ordered_options.rb +49 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/test_case.rb +5 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/testing.rb +1 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/testing/default.rb +12 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/values/time_zone.rb +181 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/values/unicode_tables.dat +0 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor.rb +14 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/version.rb +9 -0
- data/vendor/activesupport-2.0.2-/lib/active_support/whiny_nil.rb +38 -0
- data/vendor/activesupport-2.0.2-/lib/activesupport.rb +1 -0
- metadata +222 -2
data/README
CHANGED
@@ -35,7 +35,7 @@ Most method calls take parameters. Check out the
|
|
35
35
|
|
36
36
|
== You need an API key
|
37
37
|
|
38
|
-
You need an API key to perform any POST, PUT, or DELETE requests. You must also use an API key to perform a GET request to access your private or shared data. Get your API key from https://inviteonly.swivel.com/developer. Please treat your API key as you would a password.
|
38
|
+
You need an API key to perform any POST, PUT, or DELETE requests. You must also use an API key to perform a GET request to access your private or shared data. GET requests on public resources (such as users, or public data) do not require an API key. But it never hurts to always send it. Get your API key from https://inviteonly.swivel.com/developer. Please treat your API key as you would a password.
|
39
39
|
|
40
40
|
Your API key is stored in ~/.swivelrc along with some other information. Copy the swivelrc.default provided with this gem to ~/.swivelrc and modify site parameter to include your API key. Please make sure you set appropriate permissions on your ~/.swivelrc file to prevent others from seeing your API key.
|
41
41
|
|
@@ -79,6 +79,9 @@ key with each request. For example:
|
|
79
79
|
|
80
80
|
>> data_sets = connection.get '/data_sets'
|
81
81
|
|
82
|
+
You can also construct a Swivel2::Connection without passing a config option
|
83
|
+
to get a read-only connection that can only access public resources on Swivel.
|
84
|
+
|
82
85
|
=== Data sets
|
83
86
|
|
84
87
|
==== Show a data set
|
data/Rakefile
CHANGED
@@ -56,7 +56,7 @@ spec =
|
|
56
56
|
s.email = 'huned@swivel.com'
|
57
57
|
s.homepage = 'http://www.swivel.com/developer'
|
58
58
|
|
59
|
-
s.files = %w/COPYING README Rakefile/ + Dir['{lib,bin}
|
59
|
+
s.files = %w/COPYING README Rakefile/ + Dir['{lib,bin,vendor}/**/*']
|
60
60
|
s.require_path = "lib"
|
61
61
|
|
62
62
|
s.bindir = "bin"
|
data/lib/swivel.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
# benchmarking module
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Swivel2
|
5
|
+
|
6
|
+
class Config < Struct.new :site, :timeout_read, :timeout_write, :extra_params
|
7
|
+
def initialize options = {}
|
8
|
+
options.each do |k, v| self[k] = v end
|
9
|
+
end
|
10
|
+
|
11
|
+
def extra_params
|
12
|
+
super || {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def save file = nil
|
16
|
+
File.open file || Config.config_file, 'w' do |f|
|
17
|
+
YAML.dump self, f
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.load file = nil
|
22
|
+
YAML.load_file(file || config_file)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.default
|
26
|
+
@@default ||= self.load default_config_file
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def self.config_file
|
32
|
+
case PLATFORM
|
33
|
+
when /win32/
|
34
|
+
ENV['USERPROFILE'] + '\_swivelrc'
|
35
|
+
else
|
36
|
+
ENV['HOME'] + '/.swivelrc'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.default_config_file
|
41
|
+
File.dirname(__FILE__) + '/swivelrc.default'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Swivel2
|
2
|
+
|
3
|
+
class Connection
|
4
|
+
attr_reader :config, :resource, :format
|
5
|
+
|
6
|
+
def initialize config = Config.default
|
7
|
+
@config = config.is_a?(Hash) ? Config.new(config) : config
|
8
|
+
@resource = ActiveResource::Connection.new @config.site
|
9
|
+
@format = Swivel2::Formats::XmlFormat
|
10
|
+
end
|
11
|
+
|
12
|
+
def post path, params = {}, headers = {}
|
13
|
+
request :post, path, params, headers
|
14
|
+
end
|
15
|
+
|
16
|
+
def get path, params = {}, headers = {}
|
17
|
+
request :get, path, params, headers
|
18
|
+
end
|
19
|
+
|
20
|
+
def put path, params = {}, headers = {}
|
21
|
+
request :put, path, params, headers
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete path, params = {}, headers = {}
|
25
|
+
request :delete, path, params, headers
|
26
|
+
end
|
27
|
+
|
28
|
+
def call path, params = {}, method = :get, headers = {}
|
29
|
+
request method, path, params, headers
|
30
|
+
end
|
31
|
+
|
32
|
+
[ :post, :get, :put, :delete, :call ].each do |m|
|
33
|
+
define_method "#{m}!" do |*args|
|
34
|
+
returning send(m, *args) do |r|
|
35
|
+
r.raise if Swivel::Error === r
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
deprecate :call, :call!
|
41
|
+
|
42
|
+
def error exception
|
43
|
+
build format.decode(exception.response.body)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def combine path, params = {}
|
49
|
+
if params.empty?
|
50
|
+
path
|
51
|
+
else
|
52
|
+
path, qs = path.split '?'
|
53
|
+
qs = qs.blank? ? params.to_query : qs + '&' + params.to_query
|
54
|
+
[ path, qs ].join '?'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def request method, path, params = {}, headers = {}
|
59
|
+
params = params.merge config.extra_params if params.is_a? Hash
|
60
|
+
|
61
|
+
headers = default_headers.merge headers
|
62
|
+
headers = resource.send :build_request_headers, headers
|
63
|
+
|
64
|
+
response =
|
65
|
+
if method == :get || method == :delete
|
66
|
+
resource.send :request, method, combine(path, params), headers
|
67
|
+
else
|
68
|
+
params = params.to_query if params.is_a? Hash
|
69
|
+
resource.send :request, method, path, params, headers
|
70
|
+
end
|
71
|
+
build format.decode(response.body)
|
72
|
+
end
|
73
|
+
|
74
|
+
def build hash
|
75
|
+
response = Swivel2::Response.new hash.values.first
|
76
|
+
response.attributes.values.find do |v|
|
77
|
+
ActiveResource::Base === v or Array === v
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def default_headers
|
82
|
+
@@default_headers ||=
|
83
|
+
{ 'Accept' => 'application/xml',
|
84
|
+
'Content-Type' => 'application/x-www-form-urlencoded' }
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# logging module
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# make xml-simple and active resource a lot faster
|
2
|
+
begin
|
3
|
+
require 'faster_xml_simple'
|
4
|
+
class Hash
|
5
|
+
def self.from_xml_faster(xml)
|
6
|
+
undasherize_keys(typecast_xml_value(FasterXmlSimple.xml_in(xml,
|
7
|
+
'forcearray' => false,
|
8
|
+
'forcecontent' => true,
|
9
|
+
'keeproot' => true,
|
10
|
+
'contentkey' => '__content__')
|
11
|
+
))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Swivel2::Formats::XmlFormat
|
16
|
+
def decode xml
|
17
|
+
Hash.from_xml_faster xml
|
18
|
+
end
|
19
|
+
end
|
20
|
+
rescue LoadError
|
21
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
*2.0.2* (December 16th, 2007)
|
2
|
+
|
3
|
+
* Added more specific exceptions for 400, 401, and 403 (all descending from ClientError so existing rescues will work) #10326 [trek]
|
4
|
+
|
5
|
+
* Correct empty response handling. #10445 [seangeo]
|
6
|
+
|
7
|
+
|
8
|
+
*2.0.1* (December 7th, 2007)
|
9
|
+
|
10
|
+
* Don't cache net/http object so that ActiveResource is more thread-safe. Closes #10142 [kou]
|
11
|
+
|
12
|
+
* Update XML documentation examples to include explicit type attributes. Closes #9754 [hasmanyjosh]
|
13
|
+
|
14
|
+
* Added one-off declarations of mock behavior [DHH]. Example:
|
15
|
+
|
16
|
+
Before:
|
17
|
+
ActiveResource::HttpMock.respond_to do |mock|
|
18
|
+
mock.get "/people/1.xml", {}, "<person><name>David</name></person>"
|
19
|
+
end
|
20
|
+
|
21
|
+
Now:
|
22
|
+
ActiveResource::HttpMock.respond_to.get "/people/1.xml", {}, "<person><name>David</name></person>"
|
23
|
+
|
24
|
+
* Added ActiveResource.format= which defaults to :xml but can also be set to :json [DHH]. Example:
|
25
|
+
|
26
|
+
class Person < ActiveResource::Base
|
27
|
+
self.site = "http://app/"
|
28
|
+
self.format = :json
|
29
|
+
end
|
30
|
+
|
31
|
+
person = Person.find(1) # => GET http://app/people/1.json
|
32
|
+
person.name = "David"
|
33
|
+
person.save # => PUT http://app/people/1.json {name: "David"}
|
34
|
+
|
35
|
+
Person.format = :xml
|
36
|
+
person.name = "Mary"
|
37
|
+
person.save # => PUT http://app/people/1.json <person><name>Mary</name></person>
|
38
|
+
|
39
|
+
* Fix reload error when path prefix is used. #8727 [Ian Warshak]
|
40
|
+
|
41
|
+
* Remove ActiveResource::Struct because it hasn't proven very useful. Creating a new ActiveResource::Base subclass is often less code and always clearer. #8612 [Josh Peek]
|
42
|
+
|
43
|
+
* Fix query methods on resources. [Cody Fauser]
|
44
|
+
|
45
|
+
* pass the prefix_options to the instantiated record when using find without a specific id. Closes #8544 [alloy]
|
46
|
+
|
47
|
+
* Recognize and raise an exception on 405 Method Not Allowed responses. #7692 [Josh Peek]
|
48
|
+
|
49
|
+
* Handle string and symbol param keys when splitting params into prefix params and query params.
|
50
|
+
|
51
|
+
Comment.find(:all, :params => { :article_id => 5, :page => 2 }) or Comment.find(:all, :params => { 'article_id' => 5, :page => 2 })
|
52
|
+
|
53
|
+
* Added find-one with symbol [DHH]. Example: Person.find(:one, :from => :leader) # => GET /people/leader.xml
|
54
|
+
|
55
|
+
* BACKWARDS INCOMPATIBLE: Changed the finder API to be more extensible with :params and more strict usage of scopes [DHH]. Changes:
|
56
|
+
|
57
|
+
Person.find(:all, :title => "CEO") ...becomes: Person.find(:all, :params => { :title => "CEO" })
|
58
|
+
Person.find(:managers) ...becomes: Person.find(:all, :from => :managers)
|
59
|
+
Person.find("/companies/1/manager.xml") ...becomes: Person.find(:one, :from => "/companies/1/manager.xml")
|
60
|
+
|
61
|
+
* Add support for setting custom headers per Active Resource model [Rick]
|
62
|
+
|
63
|
+
class Project
|
64
|
+
headers['X-Token'] = 'foo'
|
65
|
+
end
|
66
|
+
|
67
|
+
# makes the GET request with the custom X-Token header
|
68
|
+
Project.find(:all)
|
69
|
+
|
70
|
+
* Added find-by-path options to ActiveResource::Base.find [DHH]. Examples:
|
71
|
+
|
72
|
+
employees = Person.find(:all, :from => "/companies/1/people.xml") # => GET /companies/1/people.xml
|
73
|
+
manager = Person.find("/companies/1/manager.xml") # => GET /companies/1/manager.xml
|
74
|
+
|
75
|
+
|
76
|
+
* Added support for using classes from within a single nested module [DHH]. Example:
|
77
|
+
|
78
|
+
module Highrise
|
79
|
+
class Note < ActiveResource::Base
|
80
|
+
self.site = "http://37s.sunrise.i:3000"
|
81
|
+
end
|
82
|
+
|
83
|
+
class Comment < ActiveResource::Base
|
84
|
+
self.site = "http://37s.sunrise.i:3000"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
assert_kind_of Highrise::Comment, Note.find(1).comments.first
|
89
|
+
|
90
|
+
|
91
|
+
* Added load_attributes_from_response as a way of loading attributes from other responses than just create [DHH]
|
92
|
+
|
93
|
+
class Highrise::Task < ActiveResource::Base
|
94
|
+
def complete
|
95
|
+
load_attributes_from_response(post(:complete))
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
...will set "done_at" when complete is called.
|
100
|
+
|
101
|
+
|
102
|
+
* Added support for calling custom methods #6979 [rwdaigle]
|
103
|
+
|
104
|
+
Person.find(:managers) # => GET /people/managers.xml
|
105
|
+
Kase.find(1).post(:close) # => POST /kases/1/close.xml
|
106
|
+
|
107
|
+
* Remove explicit prefix_options parameter for ActiveResource::Base#initialize. [Rick]
|
108
|
+
ActiveResource splits the prefix_options from it automatically.
|
109
|
+
|
110
|
+
* Allow ActiveResource::Base.delete with custom prefix. [Rick]
|
111
|
+
|
112
|
+
* Add ActiveResource::Base#dup [Rick]
|
113
|
+
|
114
|
+
* Fixed constant warning when fetching the same object multiple times [DHH]
|
115
|
+
|
116
|
+
* Added that saves which get a body response (and not just a 201) will use that response to update themselves [DHH]
|
117
|
+
|
118
|
+
* Disregard namespaces from the default element name, so Highrise::Person will just try to fetch from "/people", not "/highrise/people" [DHH]
|
119
|
+
|
120
|
+
* Allow array and hash query parameters. #7756 [Greg Spurrier]
|
121
|
+
|
122
|
+
* Loading a resource preserves its prefix_options. #7353 [Ryan Daigle]
|
123
|
+
|
124
|
+
* Carry over the convenience of #create from ActiveRecord. Closes #7340. [Ryan Daigle]
|
125
|
+
|
126
|
+
* Increase ActiveResource::Base test coverage. Closes #7173, #7174 [Rich Collins]
|
127
|
+
|
128
|
+
* Interpret 422 Unprocessable Entity as ResourceInvalid. #7097 [dkubb]
|
129
|
+
|
130
|
+
* Mega documentation patches. #7025, #7069 [rwdaigle]
|
131
|
+
|
132
|
+
* Base.exists?(id, options) and Base#exists? check whether the resource is found. #6970 [rwdaigle]
|
133
|
+
|
134
|
+
* Query string support. [untext, Jeremy Kemper]
|
135
|
+
# GET /forums/1/topics.xml?sort=created_at
|
136
|
+
Topic.find(:all, :forum_id => 1, :sort => 'created_at')
|
137
|
+
|
138
|
+
* Base#==, eql?, and hash methods. == returns true if its argument is identical to self or if it's an instance of the same class, is not new?, and has the same id. eql? is an alias for ==. hash delegates to id. [Jeremy Kemper]
|
139
|
+
|
140
|
+
* Allow subclassed resources to share the site info [Rick, Jeremy Kemper]
|
141
|
+
d
|
142
|
+
class BeastResource < ActiveResource::Base
|
143
|
+
self.site = 'http://beast.caboo.se'
|
144
|
+
end
|
145
|
+
|
146
|
+
class Forum < BeastResource
|
147
|
+
# taken from BeastResource
|
148
|
+
# self.site = 'http://beast.caboo.se'
|
149
|
+
end
|
150
|
+
|
151
|
+
class Topic < BeastResource
|
152
|
+
self.site += '/forums/:forum_id'
|
153
|
+
end
|
154
|
+
|
155
|
+
* Fix issues with ActiveResource collection handling. Closes #6291. [bmilekic]
|
156
|
+
|
157
|
+
* Use attr_accessor_with_default to dry up attribute initialization. References #6538. [Stuart Halloway]
|
158
|
+
|
159
|
+
* Add basic logging support for logging outgoing requests. [Jamis Buck]
|
160
|
+
|
161
|
+
* Add Base.delete for deleting resources without having to instantiate them first. [Jamis Buck]
|
162
|
+
|
163
|
+
* Make #save behavior mimic AR::Base#save (true on success, false on failure). [Jamis Buck]
|
164
|
+
|
165
|
+
* Add Basic HTTP Authentication to ActiveResource (closes #6305). [jonathan]
|
166
|
+
|
167
|
+
* Extracted #id_from_response as an entry point for customizing how a created resource gets its own ID.
|
168
|
+
By default, it extracts from the Location response header.
|
169
|
+
|
170
|
+
* Optimistic locking: raise ActiveResource::ResourceConflict on 409 Conflict response. [Jeremy Kemper]
|
171
|
+
|
172
|
+
# Example controller action
|
173
|
+
def update
|
174
|
+
@person.save!
|
175
|
+
rescue ActiveRecord::StaleObjectError
|
176
|
+
render :xml => @person.reload.to_xml, :status => '409 Conflict'
|
177
|
+
end
|
178
|
+
|
179
|
+
* Basic validation support [Rick Olson]
|
180
|
+
|
181
|
+
Parses the xml response of ActiveRecord::Errors#to_xml with a similar interface to ActiveRecord::Errors.
|
182
|
+
|
183
|
+
render :xml => @person.errors.to_xml, :status => '400 Validation Error'
|
184
|
+
|
185
|
+
* Deep hashes are converted into collections of resources. [Jeremy Kemper]
|
186
|
+
Person.new :name => 'Bob',
|
187
|
+
:address => { :id => 1, :city => 'Portland' },
|
188
|
+
:contacts => [{ :id => 1 }, { :id => 2 }]
|
189
|
+
Looks for Address and Contact resources and creates them if unavailable.
|
190
|
+
So clients can fetch a complex resource in a single request if you e.g.
|
191
|
+
render :xml => @person.to_xml(:include => [:address, :contacts])
|
192
|
+
in your controller action.
|
193
|
+
|
194
|
+
* Major updates [Rick Olson]
|
195
|
+
|
196
|
+
* Add full support for find/create/update/destroy
|
197
|
+
* Add support for specifying prefixes.
|
198
|
+
* Allow overriding of element_name, collection_name, and primary key
|
199
|
+
* Provide simpler HTTP mock interface for testing
|
200
|
+
|
201
|
+
# rails routing code
|
202
|
+
map.resources :posts do |post|
|
203
|
+
post.resources :comments
|
204
|
+
end
|
205
|
+
|
206
|
+
# ActiveResources
|
207
|
+
class Post < ActiveResource::Base
|
208
|
+
self.site = "http://37s.sunrise.i:3000/"
|
209
|
+
end
|
210
|
+
|
211
|
+
class Comment < ActiveResource::Base
|
212
|
+
self.site = "http://37s.sunrise.i:3000/posts/:post_id/"
|
213
|
+
end
|
214
|
+
|
215
|
+
@post = Post.find 5
|
216
|
+
@comments = Comment.find :all, :post_id => @post.id
|
217
|
+
|
218
|
+
@comment = Comment.new({:body => 'hello world'}, {:post_id => @post.id})
|
219
|
+
@comment.save
|
220
|
+
|
221
|
+
* Base.site= accepts URIs. 200...400 are valid response codes. PUT and POST request bodies default to ''. [Jeremy Kemper]
|
222
|
+
|
223
|
+
* Initial checkin: object-oriented client for restful HTTP resources which follow the Rails convention. [DHH]
|