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

Instance Method Summary collapse

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 <<-EOF
        RestClient.<%=api_method[:method] %> "<%= full_api_url %>", :params => <%= params %>
      EOF
    elsif ['post','put'].include? api_method[:method]
      req_code = ERB.new <<-EOF
        RestClient.<%=api_method[:method] %> "<%= full_api_url %>", params
      EOF
      puts params
    else
      # raise error if wrong method name 
      raise "Wrong http method name '#{api_method[:method]}'"
    end
     
    #puts req_code.result(binding)
    
    # Execute request
    eval req_code.result(binding)
end

.setup(account, auth_token, server = SERVER) ⇒ Object

Eagleplatform module initializator

Examples:

How to use Eagleplatform.setup()

Eagpleplatform.setup('your_account','your_auth_token')

Parameters:

  • account (String)

    Your account name

  • auth_token (String)

    Your authentication token form eagleplatform.com

  • server (String) (defaults to: SERVER)

    API server url. Default: api.eagleplatform.com



128
129
130
131
132
133
# File 'lib/eagleplatform.rb', line 128

def setup(, auth_token, server = SERVER)
    .blank? ? ( raise ArgumentError, 'account is blank') : @@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

#accountObject

Return account



39
40
41
# File 'lib/eagleplatform.rb', line 39

def 
  @@account
end