restly 0.0.1.alpha.19 → 0.0.1.alpha.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ module Restly::Base::Fields
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
5
+
5
6
  extend ClassMethods
6
7
 
7
8
  class_attribute :fields
@@ -9,23 +9,24 @@ class Restly::Base::Resource::Specification::Fields < Restly::Proxies::Base
9
9
  super Restly::Base::Fields::FieldSet.new(spec.model)
10
10
  end
11
11
 
12
- def -(field)
12
+ def - field
13
13
  @removed << field
14
- super
14
+ method_missing __method__, field
15
15
  end
16
16
 
17
- def +(field)
17
+ def + field
18
18
  @added << field
19
- super
19
+ method_missing __method__, field
20
20
  end
21
21
 
22
22
  private
23
23
 
24
24
  def method_missing(m, *args, &block)
25
- reload_specification! unless super.present?
25
+ reload_specification! if !super.present? || m == :inspect
26
26
  if (value = super).is_a? self.class
27
- __setobj__ value
28
- self
27
+ duplicate = self.dup
28
+ duplicate.__setobj__ super
29
+ duplicate
29
30
  else
30
31
  value
31
32
  end
data/lib/restly/client.rb CHANGED
@@ -1,16 +1,20 @@
1
1
  class Restly::Client < OAuth2::Client
2
2
 
3
- attr_accessor :id, :secret, :site
4
- attr_reader :format, :resource
3
+ attr_accessor :id, :secret, :site, :base_path
4
+ attr_reader :format, :resource, :site
5
5
 
6
6
  def initialize(*args, &block)
7
7
  opts = args.extract_options!
8
8
  opts.merge!(raise_errors: false)
9
9
 
10
+ # Set Resource
10
11
  self.resource = opts.delete(:resource) if opts[:resource]
11
12
  self.id = args[0] || Restly::Configuration.oauth_options[:client_id]
12
13
  self.secret = args[1] || Restly::Configuration.oauth_options[:client_secret]
14
+
15
+ # Set URL
13
16
  self.site = opts.delete(:site) || Restly::Configuration.site
17
+
14
18
  self.options = Restly::Configuration.client_options.merge(opts)
15
19
  self.ssl = opts.delete(:ssl) || Restly::Configuration.ssl
16
20
  self.format = @format = opts.delete(:format) || Restly::Configuration.default_format
@@ -31,6 +35,15 @@ class Restly::Client < OAuth2::Client
31
35
  self.options[:connection_opts][:ssl] = val if val
32
36
  end
33
37
 
38
+ def site=(val)
39
+ url = URI.parse(val)
40
+ scheme = "#{url.scheme}://"
41
+ host = url.host
42
+ port = url.port == 80 || url.port == 443 ? nil : ":#{url.port}"
43
+ @site = [scheme, host, port].compact.join
44
+ @base_path = url.path
45
+ end
46
+
34
47
  def format=(val)
35
48
  self.options[:connection_opts][:headers] = {
36
49
  "Accept" => "application/#{format}",
@@ -2,7 +2,7 @@ class Restly::Connection < OAuth2::AccessToken
2
2
 
3
3
  attr_accessor :cache, :cache_options
4
4
 
5
- delegate :resource, :resource_name, to: :client
5
+ delegate :resource, :resource_name, :base_path, to: :client
6
6
 
7
7
  # TODO: Refactor with subclasses that have their own tokenize methods.
8
8
  def self.tokenize(client, object)
@@ -64,6 +64,9 @@ class Restly::Connection < OAuth2::AccessToken
64
64
  alias_method :forced_request, :request
65
65
 
66
66
  def request(verb, path, opts={}, &block)
67
+ path = [base_path, path.gsub(/^\/?/, '')].join('/')
68
+ puts path.blue
69
+
67
70
  if cache && !opts[:force]
68
71
  request_log("Restly::CacheRequest", path, verb) do
69
72
  cached_request(verb, path, opts, &block)
@@ -1,3 +1,3 @@
1
1
  module Restly
2
- VERSION = "0.0.1.alpha.19"
2
+ VERSION = "0.0.1.alpha.22"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha.19
4
+ version: 0.0.1.alpha.22
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-20 00:00:00.000000000 Z
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth2