Class: Weeblycloud::User

Inherits:
CloudResource show all
Includes:
Saveable
Defined in:
lib/weeblycloud/user.rb

Overview

Represents a User resource. cloud-developer.weebly.com/user.html

Instance Attribute Summary

Attributes inherited from CloudResource

#properties

Instance Method Summary collapse

Methods included from Saveable

#[]=, #save, #set_property

Methods inherited from CloudResource

#[], #get_property, #to_s

Constructor Details

#initialize(user_id, data = nil) ⇒ User

Returns a new instance of User.



14
15
16
17
18
# File 'lib/weeblycloud/user.rb', line 14

def initialize(user_id, data = nil)
  @user_id = user_id.to_i
  @endpoint = "user/#{@user_id}"
  super(data)
end

Instance Method Details

#create_site(domain, properties = {}) ⇒ Object



60
61
62
63
64
# File 'lib/weeblycloud/user.rb', line 60

def create_site(domain, properties={})
  properties.merge!({"domain"=>domain})
  response = @client.post(@endpoint + "/site", :content=>properties)
  return Site.new(@user_id, response.json["site"]["site_id"])
end

#create_theme(name, zip_url) ⇒ Object



54
55
56
57
58
# File 'lib/weeblycloud/user.rb', line 54

def create_theme(name, zip_url)
  data = {"theme_name" => name, "theme_zip" => zip_url}
  response = @client.post(@endpoint + "/theme", :content=>data)
  return Theme.new(@user_id, response.json["theme_id"])
end

#disableObject



34
35
36
37
# File 'lib/weeblycloud/user.rb', line 34

def disable
  result = @client.post(@endpoint + "/disable")
  return result.json["success"]
end

#enableObject



29
30
31
32
# File 'lib/weeblycloud/user.rb', line 29

def enable
  result = @client.post(@endpoint + "/enable")
  return result.json["success"]
end

#getObject



24
25
26
27
# File 'lib/weeblycloud/user.rb', line 24

def get
  response = @client.get(@endpoint)
  @properties = response.json["user"]
end

#get_site(site_id) ⇒ Object



66
67
68
# File 'lib/weeblycloud/user.rb', line 66

def get_site(site_id)
  return Site.new(@user_id, site_id)
end

#idObject



20
21
22
# File 'lib/weeblycloud/user.rb', line 20

def id
  @user_id
end

#list_sites(filters = {}) ⇒ Object



49
50
51
52
# File 'lib/weeblycloud/user.rb', line 49

def list_sites(filters={})
  result = @client.get(@endpoint + "/site", :params=>filters)
  return result.map {|i| Site.new(@user_id, i["site_id"], i)}
end

#list_themes(filters = {}) ⇒ Object



44
45
46
47
# File 'lib/weeblycloud/user.rb', line 44

def list_themes(filters={})
  result = @client.get(@endpoint + "/theme", :params=>filters)
  return result.map {|i| Theme.new(@user_id, i["theme_id"], i)}
end


39
40
41
42
# File 'lib/weeblycloud/user.rb', line 39

def 
  result = @client.post(@endpoint + "/loginLink")
  return result.json["link"]
end