Module: WishSimple

Extended by:
Configuration
Defined in:
lib/wishsimple.rb,
lib/wishsimple/user.rb,
lib/wishsimple/error.rb,
lib/wishsimple/action.rb,
lib/wishsimple/product.rb,
lib/wishsimple/version.rb,
lib/wishsimple/resource.rb,
lib/wishsimple/configuration.rb,
lib/wishsimple/action/purchase.rb,
lib/wishsimple/response/raise_error.rb

Defined Under Namespace

Modules: Configuration, Response Classes: Action, Error, Product, Purchase, Resource, User

Constant Summary collapse

VERSION =
'0.0.1'

Constants included from Configuration

Configuration::DEFAULT_ADAPTER, Configuration::DEFAULT_API_KEY, Configuration::DEFAULT_API_VERSION, Configuration::DEFAULT_ENDPOINT, Configuration::DEFAULT_USER_AGENT, Configuration::OPTIONS_KEYS

Class Method Summary collapse

Methods included from Configuration

configure, extended, options, reset

Class Method Details

.delete(path, params = {}) ⇒ Object

Perform an HTTP DELETE request



41
42
43
# File 'lib/wishsimple.rb', line 41

def delete(path, params={})
  request(:delete, path, params)
end

.get(path, params = {}) ⇒ Object

Perform an HTTP GET request



31
32
33
# File 'lib/wishsimple.rb', line 31

def get(path, params={})
  request(:get, path, params)
end

.new(*args) ⇒ Object

Accepts (api_key, [options]) or (options) as parameters



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wishsimple.rb', line 14

def new(*args)
  options = {}

  # TODO: Raise an error when params don't match (string, [hash]) or (hash)
  if args[0].is_a? String
    options[:api_key] = args[0]
    options.merge!(args[1]) if args[1].is_a? Hash
  elsif args[0].is_a? Hash
    options = args[0]
  end

  Configuration::OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
end

.put(path, params = {}) ⇒ Object

Perform an HTTP PUT request



36
37
38
# File 'lib/wishsimple.rb', line 36

def put(path, params={})
  request(:put, path, params)
end

.request_path(path) ⇒ Object

Converts a resource path into a full API path with API version



51
52
53
# File 'lib/wishsimple.rb', line 51

def request_path(path)
  "/#{api_version}#{path}"
end

.request_url(path) ⇒ Object

Converts a path into a full API URL



46
47
48
# File 'lib/wishsimple.rb', line 46

def request_url(path)
  endpoint + request_path(path)
end