Class: Weeblycloud::CloudClient

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

Constant Summary collapse

@@api_key =
nil
@@api_secret =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, api_secret = nil) ⇒ CloudClient

Returns a new instance of CloudClient.



12
13
14
15
16
17
18
19
20
# File 'lib/weeblycloud/cloudclient/cloudclient.rb', line 12

def initialize(api_key = nil, api_secret = nil)
  if api_key || api_secret
    self.configure(api_key, api_secret)
  elsif @@api_key.nil? || @@api_secret.nil?
    raise "No API keys provided."
  end

  @BASE_API = "https://api.weeblycloud.com/"
end

Class Method Details

.configure(api_key, api_secret) ⇒ Object

Globally configure API key and secret



23
24
25
26
# File 'lib/weeblycloud/cloudclient/cloudclient.rb', line 23

def self.configure(api_key, api_secret)
  @@api_key = api_key
  @@api_secret = api_secret
end

Instance Method Details

#delete(endpoint, options = {}) ⇒ Object

Make a DELETE request



73
74
75
76
77
78
# File 'lib/weeblycloud/cloudclient/cloudclient.rb', line 73

def delete(endpoint, options={})
  ops = {:params => {}, :content => {}}
  ops.merge!(options)

  return call("DELETE", endpoint, ops[:content], ops[:params])
end

#get(endpoint, options = {}) ⇒ Object

Make a GET request



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/weeblycloud/cloudclient/cloudclient.rb', line 29

def get(endpoint, options={})
  ops = {
    :page_size => nil,
    :page => nil,
    :params => {},
    :content => {}
  }
  ops.merge!(options)
  if ops[:page_size]
    ops[:params].merge!({"page_size" => ops[:page_size]})
  end

  if ops[:page]
    ops[:params].merge!({"page" => options[:page]})
  end

  return call("GET", endpoint, ops[:content], ops[:params])
end

#patch(endpoint, options = {}) ⇒ Object

Make a PATCH request



57
58
59
60
61
62
# File 'lib/weeblycloud/cloudclient/cloudclient.rb', line 57

def patch(endpoint, options={})
  ops = {:params => {}, :content => {}}
  ops.merge!(options)

  return call("PATCH", endpoint, ops[:content], ops[:params])
end

#post(endpoint, options = {}) ⇒ Object

Make a POST request



49
50
51
52
53
54
# File 'lib/weeblycloud/cloudclient/cloudclient.rb', line 49

def post(endpoint, options={})
  ops = {:params => {}, :content => {}}
  ops.merge!(options)

  return call("POST", endpoint, ops[:content], ops[:params])
end

#put(endpoint, options = {}) ⇒ Object

Make a PUT request



65
66
67
68
69
70
# File 'lib/weeblycloud/cloudclient/cloudclient.rb', line 65

def put(endpoint, options={})
  ops = {:params => {}, :content => {}}
  ops.merge!(options)

  return call("PUT", endpoint, ops[:content], ops[:params])
end