Class: GcxApi::Site
- Inherits:
-
Object
- Object
- GcxApi::Site
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- lib/gcx_api/site.rb
Constant Summary collapse
- DEFAULTS =
{privacy: 'public', theme: 'amped'}
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#name ⇒ Object
Returns the value of attribute name.
-
#privacy ⇒ Object
Returns the value of attribute privacy.
-
#sitetype ⇒ Object
Returns the value of attribute sitetype.
-
#theme ⇒ Object
Returns the value of attribute theme.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #create ⇒ Object
- #create_endpoint ⇒ Object
- #destroy(site_name) ⇒ Object
-
#initialize(attributes = {}) ⇒ Site
constructor
A new instance of Site.
- #persisted? ⇒ Boolean
- #set_option_values(options) ⇒ Object
Constructor Details
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
11 12 13 |
# File 'lib/gcx_api/site.rb', line 11 def attributes @attributes end |
#domain ⇒ Object
Returns the value of attribute domain.
11 12 13 |
# File 'lib/gcx_api/site.rb', line 11 def domain @domain end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/gcx_api/site.rb', line 11 def name @name end |
#privacy ⇒ Object
Returns the value of attribute privacy.
11 12 13 |
# File 'lib/gcx_api/site.rb', line 11 def privacy @privacy end |
#sitetype ⇒ Object
Returns the value of attribute sitetype.
11 12 13 |
# File 'lib/gcx_api/site.rb', line 11 def sitetype @sitetype end |
#theme ⇒ Object
Returns the value of attribute theme.
11 12 13 |
# File 'lib/gcx_api/site.rb', line 11 def theme @theme end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/gcx_api/site.rb', line 11 def title @title end |
Instance Method Details
#create ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gcx_api/site.rb', line 30 def create parameters = attributes.to_json ticket = GcxApi::Cas.new.get_cas_service_ticket(create_endpoint) res = RestClient::Request.execute(:method => :post, :url => create_endpoint + '?ticket=' + ticket, :payload => parameters, :timeout => -1) { |response, request, result, &block| Rails.logger.debug request Rails.logger.debug result.inspect # check for error response if [301, 302, 307].include? response.code response.follow_redirection(request, result, &block) elsif response.code.to_i != 200 raise response.headers.inspect + response.inspect end response.to_str } community = JSON.parse(res) if community['errors'] raise community.inspect else @persisted = true return self end end |
#create_endpoint ⇒ Object
26 27 28 |
# File 'lib/gcx_api/site.rb', line 26 def create_endpoint GcxApi.gcx_url + "/wp-gcx/create-community.php" end |
#destroy(site_name) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/gcx_api/site.rb', line 69 def destroy(site_name) destroy_endpoint = GcxApi.gcx_url + "/#{site_name}/wp-gcx/delete-community.php" ticket = GcxApi::Cas.new.get_cas_service_ticket(destroy_endpoint) res = RestClient::Request.execute(:method => :post, :url => destroy_endpoint + '?ticket=' + ticket, :payload => {}, :timeout => -1) { |response, request, result, &block| Rails.logger.debug request Rails.logger.debug result.inspect # check for error response if response.code.to_i != 200 raise result.inspect end response.to_str } end |
#persisted? ⇒ Boolean
85 86 87 |
# File 'lib/gcx_api/site.rb', line 85 def persisted? @persisted end |
#set_option_values(options) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gcx_api/site.rb', line 54 def set_option_values() = (domain || GcxApi.gcx_url) + '/' + name + '/index.php' RestClient::Request.execute(:method => :post, :url => , :payload => , :timeout => -1) { |response, request, result, &block| Rails.logger.debug request Rails.logger.debug result.inspect # check for error response if response.code.to_i != 200 raise response.headers.inspect + response.inspect end response.to_str } end |