class Spigot::Proxy

Attributes

resource[R]
Proxy

Spigot::Proxy provides accessor methods used by the implementation that could be useful for development or custom behavior

Usage:

User.spigot.find_or_create(data)

User.spigot(:twitter).find_or_create(data)

service[R]
Proxy

Spigot::Proxy provides accessor methods used by the implementation that could be useful for development or custom behavior

Usage:

User.spigot.find_or_create(data)

User.spigot(:twitter).find_or_create(data)

Public Class Methods

new(resource, service = nil) click to toggle source
#initialize(resource)

Method to initialize a proxy.

@param service [String] This is the service that dictates the proxy. @param resource [Object] This is the class implementing the proxy.

# File lib/spigot/proxy.rb, line 21
def initialize(resource, service = nil)
  @service  = service
  @resource = resource
end

Public Instance Methods

create(params = {}) click to toggle source

create Alias for create_by_api

# File lib/spigot/proxy.rb, line 40
def create(params = {})
  resource.create_by_api service_scoped(params)
end
create_or_update(params = {}) click to toggle source

create_or_update Alias for create_or_update_by_api

# File lib/spigot/proxy.rb, line 58
def create_or_update(params = {})
  resource.create_or_update_by_api service_scoped(params)
end
find(params = {}) click to toggle source

find Alias for find_by_api

# File lib/spigot/proxy.rb, line 28
def find(params = {})
  resource.find_by_api service_scoped(params)
end
find_all(params = {}) click to toggle source

find_all Alias for find_all_by_api

# File lib/spigot/proxy.rb, line 34
def find_all(params = {})
  resource.find_all_by_api service_scoped(params)
end
find_or_create(params = {}) click to toggle source

find_or_create Alias for find_or_create_by_api

# File lib/spigot/proxy.rb, line 52
def find_or_create(params = {})
  resource.find_or_create_by_api service_scoped(params)
end
map() click to toggle source
#map

Return a hash of the data map the current translator is using

# File lib/spigot/proxy.rb, line 70
def map
  translator.resource_map
end
options() click to toggle source
#options

Return a hash of any service specific options for this translator. `Spigot.config` not included

# File lib/spigot/proxy.rb, line 82
def options
  translator.options || {}
end
present?() click to toggle source
#present?

Returns a boolean if the current spigot map has a mapping for the current resource

# File lib/spigot/proxy.rb, line 76
def present?
  translator.resource_map?(resource)
end
translator() click to toggle source
#translator

Instantiate a Spigot::Translator object with the contextual service and resource

# File lib/spigot/proxy.rb, line 64
def translator
  Translator.new(resource, service)
end
update(params = {}) click to toggle source

update Alias for update_by_api

# File lib/spigot/proxy.rb, line 46
def update(params = {})
  resource.update_by_api service_scoped(params)
end

Private Instance Methods

service_scoped(params = {}) click to toggle source
# File lib/spigot/proxy.rb, line 88
def service_scoped(params = {})
  return params if @service.nil?
  return { @service => params } if Spigot.config.map.nil?

  key, data = Spigot::Map::Service.extract(params)
  return { @service => params } if key.nil?

  if key.to_sym != @service.to_sym
    raise Spigot::InvalidServiceError, 'You cannot specify two services'
  end

  { key => data }
end