Class: WooCommerce::API

Inherits:
Object
  • Object
show all
Defined in:
lib/woocommerce_api.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, consumer_key, consumer_secret, args = {}) ⇒ API

Returns a new instance of API.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/woocommerce_api.rb', line 10

def initialize url, consumer_key, consumer_secret, args = {}
  # Required args
  @url = url
  @consumer_key = consumer_key
  @consumer_secret = consumer_secret

  # Optional args
  defaults = {
    wp_api: false,
    version: "v3",
    verify_ssl: true,
    signature_method: "HMAC-SHA256",
    httparty_args: {}
  }
  args = defaults.merge(args)

  @wp_api = args[:wp_api]
  @version = args[:version]
  @verify_ssl = args[:verify_ssl] == true
  @signature_method = args[:signature_method]
  @debug_mode = args[:debug_mode]
  @query_string_auth = args[:query_string_auth]
  @httparty_args = args[:httparty_args]

  # Internal args
  @is_ssl = @url.start_with? "https"
end

Instance Method Details

#delete(endpoint, query = nil) ⇒ Object

Public: DELETE requests.

endpoint - A String naming the request endpoint. query - A Hash with query params.

Returns the request Hash.



74
75
76
# File 'lib/woocommerce_api.rb', line 74

def delete endpoint, query = nil
  do_request :delete, add_query_params(endpoint, query)
end

#get(endpoint, query = nil) ⇒ Object

Public: GET requests.

endpoint - A String naming the request endpoint. query - A Hash with query params.

Returns the request Hash.



44
45
46
# File 'lib/woocommerce_api.rb', line 44

def get endpoint, query = nil
  do_request :get, add_query_params(endpoint, query)
end

#options(endpoint) ⇒ Object

Public: OPTIONS requests.

endpoint - A String naming the request endpoint.

Returns the request Hash.



83
84
85
# File 'lib/woocommerce_api.rb', line 83

def options endpoint
  do_request :options, add_query_params(endpoint, nil)
end

#post(endpoint, data) ⇒ Object

Public: POST requests.

endpoint - A String naming the request endpoint. data - The Hash data for the request.

Returns the request Hash.



54
55
56
# File 'lib/woocommerce_api.rb', line 54

def post endpoint, data
  do_request :post, endpoint, data
end

#put(endpoint, data) ⇒ Object

Public: PUT requests.

endpoint - A String naming the request endpoint. data - The Hash data for the request.

Returns the request Hash.



64
65
66
# File 'lib/woocommerce_api.rb', line 64

def put endpoint, data
  do_request :put, endpoint, data
end