class PhoneGap::Build::RestResource
Attributes
errors[W]
id[R]
poll_interval[RW]
poll_time_limit[RW]
Public Class Methods
new(params = {})
click to toggle source
Calls superclass method
PhoneGap::Build::Base::new
# File lib/phone_gap/build/rest_resource.rb, line 13 def initialize(params = {}) @poll_time_limit = 120 @poll_interval = 5 super(params) end
Public Instance Methods
as_json(params = {})
click to toggle source
# File lib/phone_gap/build/rest_resource.rb, line 42 def as_json(params = {}) if params[:only] json = params[:only].inject({}) do | memo, attribute_name| memo[attribute_name[1..-1].to_sym] = instance_variable_get(attribute_name) memo end else json = {} end params[:remove_nils] ? json.delete_if {|k, v| v.nil? } : json end
create()
click to toggle source
# File lib/phone_gap/build/rest_resource.rb, line 19 def create response = ApiRequest.new.post(path, post_options) if response.success? populate_from_json(JSON.parse(response.body)) self else update_errors(JSON.parse(response.body)) false end end
destroy()
click to toggle source
# File lib/phone_gap/build/rest_resource.rb, line 38 def destroy ApiRequest.new.delete(path) end
errors()
click to toggle source
# File lib/phone_gap/build/rest_resource.rb, line 54 def errors @errors ||= [] end
save()
click to toggle source
# File lib/phone_gap/build/rest_resource.rb, line 34 def save @id ? update : create end
update()
click to toggle source
# File lib/phone_gap/build/rest_resource.rb, line 30 def update ApiRequest.new.put(path, query: {data: as_json(only: updatable_attributes)}) end
Private Instance Methods
path()
click to toggle source
# File lib/phone_gap/build/rest_resource.rb, line 64 def path @id ? "#{self.class.const_get('PATH')}/#{@id}" : "#{self.class.const_get('PATH')}" end
populate_from_json(json)
click to toggle source
# File lib/phone_gap/build/rest_resource.rb, line 72 def populate_from_json(json) json.each do |key, value| if respond_to?("#{key}=") send("#{key}=", value) else instance_variable_set("@#{key}", value) end end end
post_options()
click to toggle source
# File lib/phone_gap/build/rest_resource.rb, line 60 def post_options { query: { data: as_json(only: creatable_attributes) } } end
token()
click to toggle source
# File lib/phone_gap/build/rest_resource.rb, line 68 def token PhoneGap::Build::Credentials.instance.token end
update_errors(json)
click to toggle source
# File lib/phone_gap/build/rest_resource.rb, line 82 def update_errors(json) errors << json['error'] end