Module: Eagleplatform
- Defined in:
- lib/eagleplatform.rb,
lib/eagleplatform/filter.rb,
lib/eagleplatform/record.rb,
lib/eagleplatform/version.rb,
lib/eagleplatform/translation.rb,
lib/eagleplatform/eagleplatform_object.rb
Overview
To use this library you must do:
require 'eagleplatform'
Eagleplatform.setup('account','auth_token')
# Update record fields:
record = Eagleplatform::Record.find(1234)
record.description = 'Very fun record'
record.update
# Close all translations:
Eagleplatform::Translation.all.each do |translation|
translation.delete
end
Defined Under Namespace
Modules: Methods Classes: EagleplatformObject, Filter, Record, Translation
Constant Summary collapse
- SERVER =
API server url
"api.eagleplatform.com"
- DATE_FORMAT =
Date format: ‘dd.mm.yyyy’ => ‘18.5.2012’
Regexp.new(/^([0-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])\.([0-9]|0[1-9]|1[0-2])\.(19|20)\d\d$/)
- VERSION =
"0.0.1"
Class Method Summary collapse
- .call_api(api_method, params = {}) ⇒ Object private
- .call_api_raw(api_method, params = {}) ⇒ Object private
- .request(api_method, params = {}) ⇒ Object private
-
.setup(account, auth_token, server = SERVER) ⇒ Object
Eagleplatform module initializator.
Instance Method Summary collapse
-
#account ⇒ Object
Return account.
Class Method Details
.call_api(api_method, params = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/eagleplatform.rb', line 99 def call_api(api_method, params = {}) response = call_api_raw(api_method, params) root = JSON.parse(response) #Check if there was an error unless root.empty? raise "Call_API ERROR: #{root['error']}" if root['error'] # code = result.elements['code'].text # message = result.elements['msg'].text # bad_request = result.elements['your_request'].to_s # raise EagleError.new(code, message, bad_request) end root['data'] ? (data = root['data']) : (raise 'Not include data') return data end |
.call_api_raw(api_method, params = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
116 117 118 |
# File 'lib/eagleplatform.rb', line 116 def call_api_raw(api_method, params = {}) request(api_method, params).body end |
.request(api_method, params = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/eagleplatform.rb', line 68 def request(api_method, params = {}) # Add other required params. params['account'] = @@account || ( raise "You must set account" ) params['auth_token'] = @@auth_token || ( raise "You must set auth_token" ) raise "Wrong api_method param" if api_method[:method].blank? || api_method[:path].blank? full_api_url = @@api_url.to_s+api_method[:path] #params.each_pair { |k,v| params[k]=v.to_s} # Check method name and render request if ['get','delete'].include? api_method[:method] req_code = ERB.new " RestClient.<%=api_method[:method] %> \"<%= full_api_url %>\", :params => <%= params %>\n EOF\n elsif ['post','put'].include? api_method[:method]\n req_code = ERB.new <<-EOF\n RestClient.<%=api_method[:method] %> \"<%= full_api_url %>\", params\n EOF\n puts params\n else\n # raise error if wrong method name \n raise \"Wrong http method name '\#{api_method[:method]}'\"\n end\n \n #puts req_code.result(binding)\n \n # Execute request\n eval req_code.result(binding)\nend\n" |
.setup(account, auth_token, server = SERVER) ⇒ Object
Eagleplatform module initializator
128 129 130 131 132 133 |
# File 'lib/eagleplatform.rb', line 128 def setup(account, auth_token, server = SERVER) account.blank? ? ( raise ArgumentError, 'account is blank') : @@account = account auth_token.blank? ? ( raise ArgumentError, 'auth_token is blank') : @@auth_token = auth_token server.blank? ? ( raise ArgumentError, 'server is blank' ) : server.slice!('http://') @@api_url = URI.parse("http://#{server}") end |
Instance Method Details
#account ⇒ Object
Return account
39 40 41 |
# File 'lib/eagleplatform.rb', line 39 def account @@account end |