eagleplatform 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +9 -0
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/.yardoc/checksums +6 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/doc/.yardoc/checksums +0 -0
- data/doc/.yardoc/objects/root.dat +0 -0
- data/doc/.yardoc/proxy_types +0 -0
- data/doc/Eagleplatform.html +413 -0
- data/doc/Eagleplatform/EagleplatformObject.html +224 -0
- data/doc/Eagleplatform/Filter.html +1009 -0
- data/doc/Eagleplatform/Methods.html +181 -0
- data/doc/Eagleplatform/Record.html +1497 -0
- data/doc/Eagleplatform/Translation.html +1103 -0
- data/doc/Hash.html +210 -0
- data/doc/_index.html +157 -0
- data/doc/class_list.html +47 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +55 -0
- data/doc/css/style.css +322 -0
- data/doc/doc/_index.html +84 -0
- data/doc/doc/class_list.html +47 -0
- data/doc/doc/css/common.css +1 -0
- data/doc/doc/css/full_list.css +55 -0
- data/doc/doc/css/style.css +322 -0
- data/doc/doc/file_list.html +46 -0
- data/doc/doc/frames.html +13 -0
- data/doc/doc/index.html +84 -0
- data/doc/doc/js/app.js +205 -0
- data/doc/doc/js/full_list.js +173 -0
- data/doc/doc/js/jquery.js +16 -0
- data/doc/doc/method_list.html +46 -0
- data/doc/doc/top-level-namespace.html +95 -0
- data/doc/file_list.html +46 -0
- data/doc/frames.html +13 -0
- data/doc/index.html +157 -0
- data/doc/js/app.js +205 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +16 -0
- data/doc/method_list.html +262 -0
- data/doc/top-level-namespace.html +105 -0
- data/eagleplatform.gemspec +22 -0
- data/eagleplatform.tmproj +138 -0
- data/lib/.yardoc/checksums +1 -0
- data/lib/.yardoc/objects/root.dat +0 -0
- data/lib/.yardoc/proxy_types +0 -0
- data/lib/eagleplatform.rb +135 -0
- data/lib/eagleplatform/eagleplatform_object.rb +10 -0
- data/lib/eagleplatform/filter.rb +125 -0
- data/lib/eagleplatform/record.rb +207 -0
- data/lib/eagleplatform/translation.rb +163 -0
- data/lib/eagleplatform/version.rb +3 -0
- data/spec/eagleplatform_spec.rb +146 -0
- metadata +135 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
eagleplatform.rb d9f47e9e8db5fd762a8727e59b91140d87045f6f
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require 'active_support/core_ext'
|
|
2
|
+
require 'rest_client'
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'json'
|
|
5
|
+
require "erb"
|
|
6
|
+
|
|
7
|
+
require "eagleplatform/eagleplatform_object"
|
|
8
|
+
require "eagleplatform/record"
|
|
9
|
+
require "eagleplatform/translation"
|
|
10
|
+
require "eagleplatform/filter"
|
|
11
|
+
require "eagleplatform/version"
|
|
12
|
+
|
|
13
|
+
# @api private
|
|
14
|
+
class Hash
|
|
15
|
+
# @return [Hash] Return Hash with symbolic keys
|
|
16
|
+
def to_sym_hash
|
|
17
|
+
self.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# To use this library you must do:
|
|
22
|
+
# require 'eagleplatform'
|
|
23
|
+
# Eagleplatform.setup('account','auth_token')
|
|
24
|
+
#
|
|
25
|
+
# # Update record fields:
|
|
26
|
+
# record = Eagleplatform::Record.find(1234)
|
|
27
|
+
# record.description = 'Very fun record'
|
|
28
|
+
# record.update
|
|
29
|
+
#
|
|
30
|
+
# # Close all translations:
|
|
31
|
+
# Eagleplatform::Translation.all.each do |translation|
|
|
32
|
+
# translation.delete
|
|
33
|
+
# end
|
|
34
|
+
# @see setup
|
|
35
|
+
module Eagleplatform
|
|
36
|
+
@@account, @@auth_token, @@api_url = nil
|
|
37
|
+
|
|
38
|
+
# Return account
|
|
39
|
+
def account
|
|
40
|
+
@@account
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
SERVER = "api.eagleplatform.com" # API server url
|
|
44
|
+
# Date format: 'dd.mm.yyyy' => '18.5.2012'
|
|
45
|
+
DATE_FORMAT = 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$/)
|
|
46
|
+
|
|
47
|
+
# Methods list provided by eaglelatform API
|
|
48
|
+
module Methods
|
|
49
|
+
TRANSLATIONS_GET_LIST = { method: "get", path: "/streaming/translations.json"}
|
|
50
|
+
TRANSLATION_GET_INFO = { method: "get", path: "/streaming/translations/:id.json"}
|
|
51
|
+
TRANSLATION_DELETE = { method: "delete", path: "/streaming/translations/:id.json"}
|
|
52
|
+
TRANSLATION_UPDATE = { method: "put", path: "/streaming/translations/:id.json"}
|
|
53
|
+
TRANSLATION_GET_STATISTICS = { method: "get", path: "/streaming/translations/:id/statistics.json"}
|
|
54
|
+
|
|
55
|
+
RECORDS_GET_STATISTICS = { method: "get", path: "/media/records/statistics.json"}
|
|
56
|
+
RECORD_GET_STATISTICS = { method: "get", path: "/media/records/:id/statistics.json"}
|
|
57
|
+
RECORD_GET_INFO = { method: "get", path: "/media/records/:id.json"}
|
|
58
|
+
RECORD_UPDATE = { method: "put", path: "/media/records/:id.json"}
|
|
59
|
+
RECORD_DELETE = { method: "delete", path: "/media/records/:id.json"}
|
|
60
|
+
RECORD_UPLOAD_FROM_FTP = { method: "post", path: "/media/records.json"}
|
|
61
|
+
RECORD_UPLOAD_FROM_HTTP = { method: "post", path: "/media/records.json"}
|
|
62
|
+
|
|
63
|
+
FILTER_GET_RECORDS = { method: "get", path: "/media/filters/:id.json"}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class << self
|
|
67
|
+
# @api private
|
|
68
|
+
def request(api_method, params = {})
|
|
69
|
+
# Add other required params.
|
|
70
|
+
params['account'] = @@account || ( raise "You must set account" )
|
|
71
|
+
params['auth_token'] = @@auth_token || ( raise "You must set auth_token" )
|
|
72
|
+
raise "Wrong api_method param" if api_method[:method].blank? || api_method[:path].blank?
|
|
73
|
+
full_api_url = @@api_url.to_s+api_method[:path]
|
|
74
|
+
|
|
75
|
+
#params.each_pair { |k,v| params[k]=v.to_s}
|
|
76
|
+
|
|
77
|
+
# Check method name and render request
|
|
78
|
+
if ['get','delete'].include? api_method[:method]
|
|
79
|
+
req_code = ERB.new <<-EOF
|
|
80
|
+
RestClient.<%=api_method[:method] %> "<%= full_api_url %>", :params => <%= params %>
|
|
81
|
+
EOF
|
|
82
|
+
elsif ['post','put'].include? api_method[:method]
|
|
83
|
+
req_code = ERB.new <<-EOF
|
|
84
|
+
RestClient.<%=api_method[:method] %> "<%= full_api_url %>", params
|
|
85
|
+
EOF
|
|
86
|
+
puts params
|
|
87
|
+
else
|
|
88
|
+
# raise error if wrong method name
|
|
89
|
+
raise "Wrong http method name '#{api_method[:method]}'"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
#puts req_code.result(binding)
|
|
93
|
+
|
|
94
|
+
# Execute request
|
|
95
|
+
eval req_code.result(binding)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# @api private
|
|
99
|
+
def call_api(api_method, params = {})
|
|
100
|
+
response = call_api_raw(api_method, params)
|
|
101
|
+
root = JSON.parse(response)
|
|
102
|
+
|
|
103
|
+
#Check if there was an error
|
|
104
|
+
unless root.empty?
|
|
105
|
+
raise "Call_API ERROR: #{root['error']}" if root['error']
|
|
106
|
+
# code = result.elements['code'].text
|
|
107
|
+
# message = result.elements['msg'].text
|
|
108
|
+
# bad_request = result.elements['your_request'].to_s
|
|
109
|
+
# raise EagleError.new(code, message, bad_request)
|
|
110
|
+
end
|
|
111
|
+
root['data'] ? (data = root['data']) : (raise 'Not include data')
|
|
112
|
+
return data
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# @api private
|
|
116
|
+
def call_api_raw(api_method, params = {})
|
|
117
|
+
request(api_method, params).body
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
##
|
|
121
|
+
# Eagleplatform module initializator
|
|
122
|
+
# @example How to use Eagleplatform.setup()
|
|
123
|
+
# Eagpleplatform.setup('your_account','your_auth_token')
|
|
124
|
+
# @param [String] account Your account name
|
|
125
|
+
# @param [String] auth_token Your authentication token form eagleplatform.com
|
|
126
|
+
# @param [String] server API server url. Default: api.eagleplatform.com
|
|
127
|
+
##
|
|
128
|
+
def setup(account, auth_token, server = SERVER)
|
|
129
|
+
account.blank? ? ( raise ArgumentError, 'account is blank') : @@account = account
|
|
130
|
+
auth_token.blank? ? ( raise ArgumentError, 'auth_token is blank') : @@auth_token = auth_token
|
|
131
|
+
server.blank? ? ( raise ArgumentError, 'server is blank' ) : server.slice!('http://')
|
|
132
|
+
@@api_url = URI.parse("http://#{server}")
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
module Eagleplatform
|
|
2
|
+
# Filters
|
|
3
|
+
# @example
|
|
4
|
+
# # Simple request:
|
|
5
|
+
# f = Eagleplatform::Filter.find(54321)
|
|
6
|
+
#
|
|
7
|
+
# # With custom records count per page:
|
|
8
|
+
# f = Eagleplatform::Filter.find(54321, 100 )
|
|
9
|
+
#
|
|
10
|
+
# # With custom records count per page and custom page number:
|
|
11
|
+
# f = Eagleplatform::Filter.find(54321, 50, 3 )
|
|
12
|
+
#
|
|
13
|
+
# f.current_page
|
|
14
|
+
# => '3'
|
|
15
|
+
# f.records.count
|
|
16
|
+
# => '50'
|
|
17
|
+
#
|
|
18
|
+
# f.next_page
|
|
19
|
+
# => '+ 50 records loaded'
|
|
20
|
+
#
|
|
21
|
+
# f.current_page
|
|
22
|
+
# => '4'
|
|
23
|
+
# # f.records.count
|
|
24
|
+
# => '100'
|
|
25
|
+
#
|
|
26
|
+
# # List of records name with create date :
|
|
27
|
+
# f.records.each { |rec| puts "name: #{rec.name} created_at: #{rec.created_at}" }
|
|
28
|
+
class Filter
|
|
29
|
+
attr_reader :id, :name, :total_entries, :current_page, :total_pages, :per_page
|
|
30
|
+
|
|
31
|
+
# List of loaded records
|
|
32
|
+
# @return [Array] List of loaded records
|
|
33
|
+
def records
|
|
34
|
+
@records
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# @api private
|
|
38
|
+
def initialize(result)
|
|
39
|
+
@id = result['id']
|
|
40
|
+
@name = result['name']
|
|
41
|
+
@total_entries = result['total_entries']
|
|
42
|
+
@total_pages = result['total_pages']
|
|
43
|
+
@current_page = result['current_page']
|
|
44
|
+
|
|
45
|
+
@records = []
|
|
46
|
+
result['records'].each do |record|
|
|
47
|
+
rec = Eagleplatform::Record.new
|
|
48
|
+
rec.each_pair { |k,v| rec[k] = record[k.to_s]}
|
|
49
|
+
@records.push(rec)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
notice = <<-EOF
|
|
53
|
+
#####################################################
|
|
54
|
+
ATTENTION - There is more then one page
|
|
55
|
+
method 'next_page' load more records
|
|
56
|
+
See: total_pages, current_page and total_enteries
|
|
57
|
+
#####################################################
|
|
58
|
+
EOF
|
|
59
|
+
puts notice if @total_pages > 1
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
##
|
|
63
|
+
# Load records form filter next page
|
|
64
|
+
# @example
|
|
65
|
+
# f = Eagleplatform::Filter.find(54321)
|
|
66
|
+
# f.next_page
|
|
67
|
+
# @return [String] Count of loaded records
|
|
68
|
+
def next_page
|
|
69
|
+
if @current_page < @total_pages
|
|
70
|
+
begin
|
|
71
|
+
@current_page += 1
|
|
72
|
+
params = {
|
|
73
|
+
page: @current_page.to_s,
|
|
74
|
+
per_page: @per_page.to_s
|
|
75
|
+
}
|
|
76
|
+
api_method = {method: Methods::FILTER_GET_RECORDS[:method],
|
|
77
|
+
path: Methods::FILTER_GET_RECORDS[:path].gsub(':id', self.id.to_s)}
|
|
78
|
+
result = Eagleplatform.call_api(api_method, params)
|
|
79
|
+
result['records'].each do |record|
|
|
80
|
+
rec = Eagleplatform::Record.new
|
|
81
|
+
rec.each_pair { |k,v| rec[k] = record[k.to_s]}
|
|
82
|
+
@records.push(rec)
|
|
83
|
+
end
|
|
84
|
+
puts "+#{result['records'].count} records loaded."
|
|
85
|
+
rescue Exception => e
|
|
86
|
+
@current_page -= 1
|
|
87
|
+
puts e
|
|
88
|
+
end
|
|
89
|
+
elsif @current_page == @total_pages
|
|
90
|
+
puts "@current_page == @total_pages. Nothing to load"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
##
|
|
95
|
+
# Get records form filter
|
|
96
|
+
# @param [Numeric] id ID of filter
|
|
97
|
+
# @param [Numeric] per_page Records per page
|
|
98
|
+
# @param [Numeric] page Records page number
|
|
99
|
+
# @example
|
|
100
|
+
# # Simple request:
|
|
101
|
+
# f = Eagleplatform::Filter.find(54321)
|
|
102
|
+
#
|
|
103
|
+
# # With custom records count per page:
|
|
104
|
+
# f = Eagleplatform::Filter.find(54321, 100 )
|
|
105
|
+
#
|
|
106
|
+
# # With custom records count per page and custom page number:
|
|
107
|
+
# f = Eagleplatform::Filter.find(54321, 50, 3 )
|
|
108
|
+
# @return [Eagleplatform::Filter] if filetr present
|
|
109
|
+
# @raise [ArgumentError] id must be numeric
|
|
110
|
+
def self.find(id, per_page = 50, page = 1)
|
|
111
|
+
raise 'per_page must be betwen 1 to 1000' unless per_page.between?(1,1000)
|
|
112
|
+
raise ArgumentError, 'id must be numeric' unless id.is_a? Numeric
|
|
113
|
+
params = {
|
|
114
|
+
page: page.to_s,
|
|
115
|
+
per_page: per_page.to_s
|
|
116
|
+
}
|
|
117
|
+
api_method = {method: Methods::FILTER_GET_RECORDS[:method],
|
|
118
|
+
path: Methods::FILTER_GET_RECORDS[:path].gsub(':id',id.to_s)}
|
|
119
|
+
result = Eagleplatform.call_api(api_method, params)
|
|
120
|
+
filter = self.new(result)
|
|
121
|
+
filter.instance_eval("@per_page = #{per_page}")
|
|
122
|
+
filter
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
module Eagleplatform
|
|
2
|
+
# Records
|
|
3
|
+
class Record < EagleplatformObject.new(:id, :name, :description, :duration, :origin,
|
|
4
|
+
:origin_size, :updated_at, :is_processed, :screenshot,
|
|
5
|
+
:view_count, :click_url, :user_id, :recorded_at,
|
|
6
|
+
:created_at, :tags, :record_files)
|
|
7
|
+
##
|
|
8
|
+
# Find Record by ID
|
|
9
|
+
# @param [Numeric] id ID of record
|
|
10
|
+
# @example
|
|
11
|
+
# Eagleplatform::Record.find(45632)
|
|
12
|
+
# @return [Eagleplaform::Record] if record present
|
|
13
|
+
# # @raise [ArgumentError] id must be numeric
|
|
14
|
+
def self.find(id)
|
|
15
|
+
raise ArgumentError, 'id must be numeric' unless id.is_a? Numeric
|
|
16
|
+
api_method = {method: Methods::RECORD_GET_INFO[:method],
|
|
17
|
+
path: Methods::RECORD_GET_INFO[:path].gsub(':id',id.to_s)}
|
|
18
|
+
result = Eagleplatform.call_api(api_method).first[1].to_options
|
|
19
|
+
rec = self.new
|
|
20
|
+
rec.each_pair { |k,v| rec[k] = result[k] }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
##
|
|
25
|
+
# Create record and upload file form ftp server
|
|
26
|
+
# @param [Hash] args the ftp options to upload video
|
|
27
|
+
# @option args [Hash] :ftp
|
|
28
|
+
# server: 'ftp_server',
|
|
29
|
+
# file_path: 'file_path',
|
|
30
|
+
# username: 'user',
|
|
31
|
+
# password: 'pass'
|
|
32
|
+
# @option args [Hash] :record
|
|
33
|
+
# name: 'record_name'
|
|
34
|
+
# description: 'record_description'
|
|
35
|
+
# @example
|
|
36
|
+
# record_params = { name: 'SomeRecord', description: 'Example Video' }
|
|
37
|
+
# ftp_params = { server: 'ftp.example_server.com',file_path: '/videos/my_video.mpg',username: 'ftp_username', password: 'ftp_passowrd' }
|
|
38
|
+
# Eagleplatform::Record.upload_form_ftp( record: record_params, ftp: ftp_params)
|
|
39
|
+
# @return [Eagleplatform::Record] return Record object if record created
|
|
40
|
+
def self.upload_from_ftp(args)
|
|
41
|
+
raise ArgumentError, "record[:name] is blank" if args[:record][:name].blank?
|
|
42
|
+
raise ArgumentError, "ftp[:server] is blank" if args[:ftp][:server].blank?
|
|
43
|
+
raise ArgumentError, "ftp[:file_path] is blank" if args[:ftp][:file_path].blank?
|
|
44
|
+
params = {
|
|
45
|
+
record: args[:record],
|
|
46
|
+
source: {
|
|
47
|
+
type: 'ftp',
|
|
48
|
+
parameters: {
|
|
49
|
+
host: args[:ftp][:server],
|
|
50
|
+
file: args[:ftp][:file_path],
|
|
51
|
+
username: args[:ftp][:username] || "ftp",
|
|
52
|
+
password: args[:ftp][:password] || ""
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
result = Eagleplatform.call_api(Methods::RECORD_UPLOAD_FROM_FTP, params).first[1].to_options
|
|
57
|
+
rec = self.new
|
|
58
|
+
rec.each_pair { |k,v| rec[k] = result[k]}
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
##
|
|
63
|
+
# Update record on Eagleplatform
|
|
64
|
+
# @param [Hash] record Hash of record fields
|
|
65
|
+
# @option record [String] :id
|
|
66
|
+
# @option record [String] :name
|
|
67
|
+
# @option record [String] :description
|
|
68
|
+
# @example
|
|
69
|
+
# Eagleplatform::Record.update(id: 1234, name: 'Hello world', description: 'Heyy')
|
|
70
|
+
# @return [Hash] Updated record
|
|
71
|
+
def self.update(args = {})
|
|
72
|
+
raise ArgumentError, 'ID is blank' if args[:id].blank?
|
|
73
|
+
raise ArgumentError, 'id must be numeric' unless args[:id].is_a? Numeric
|
|
74
|
+
params = {
|
|
75
|
+
record: args
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
api_method = {method: Methods::RECORD_UPDATE[:method],
|
|
79
|
+
path: Methods::RECORD_UPDATE[:path].gsub(':id',args[:id].to_s)}
|
|
80
|
+
result = Eagleplatform.call_api(api_method, params).first[1].to_options
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
##
|
|
85
|
+
# Delete record from Eagleplatform
|
|
86
|
+
# @example
|
|
87
|
+
# Eagleplatform::Record.delete(1234)
|
|
88
|
+
# @return [String] 'Record id: #{id} is deleted' if record deleted successfully
|
|
89
|
+
def self.delete(id)
|
|
90
|
+
raise ArgumentError, 'id must be numeric' unless id.is_a? Numeric
|
|
91
|
+
api_method = {method: Methods::RECORD_DELETE[:method],
|
|
92
|
+
path: Methods::RECORD_DELETE[:path].gsub(':id',id.to_s)}
|
|
93
|
+
Eagleplatform.call_api(api_method) == "ok" ? "Record id: '#{id}' is deleted" : (raise "Can't delete record")
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
##
|
|
98
|
+
# Create record and upload file form http server
|
|
99
|
+
# @param [Hash] args the http options to upload video
|
|
100
|
+
# @option args [String] :upload_url
|
|
101
|
+
# @option args [Hash] :record
|
|
102
|
+
# name: 'record_name'
|
|
103
|
+
# description: 'record_description'
|
|
104
|
+
# @example
|
|
105
|
+
# record_params = { name: 'SomeRecord', description: 'Example Video' }
|
|
106
|
+
# Eagleplatform::Record.upload_form_http( record: record_params, upload_url: 'http://exapmle.com/video.mpg')
|
|
107
|
+
# @return [Eagleplatform::Record] return Record object if record created
|
|
108
|
+
def self.upload_from_http(args)
|
|
109
|
+
raise ArgumentError, "record[:name] is blank" if args[:record][:name].blank?
|
|
110
|
+
raise ArgumentError, "upload_url is blank" if args[:upload_url].blank?
|
|
111
|
+
params = {
|
|
112
|
+
record: args[:record],
|
|
113
|
+
source: {
|
|
114
|
+
type: 'http',
|
|
115
|
+
parameters: { url: args[:upload_url] }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
result = Eagleplatform.call_api(Methods::RECORD_UPLOAD_FROM_HTTP, params).first[1].to_options
|
|
119
|
+
rec = self.new
|
|
120
|
+
rec.each_pair { |k,v| rec[k] = result[k]}
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
##
|
|
124
|
+
# Update record on Eagleplatform
|
|
125
|
+
# @example
|
|
126
|
+
# record = Eagleplatform::Record.find(1234)
|
|
127
|
+
# record.description = 'Very fun record'
|
|
128
|
+
# record.update
|
|
129
|
+
# @return [Eagleplatform::Record] if record successfully updated
|
|
130
|
+
def update
|
|
131
|
+
api_method = {method: Methods::RECORD_UPDATE[:method],
|
|
132
|
+
path: Methods::RECORD_UPDATE[:path].gsub(':id',id.to_s)}
|
|
133
|
+
params = {}
|
|
134
|
+
params[:record] = self.to_hash
|
|
135
|
+
params[:record].delete(:record_files)
|
|
136
|
+
result = Eagleplatform.call_api(api_method, params).first[1].to_options
|
|
137
|
+
self.to_hash.diff(result).keys.include?(:updated_at) ? self : 'Something wrong'
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
##
|
|
141
|
+
# Delete record from Eagleplaform
|
|
142
|
+
# @example
|
|
143
|
+
# record = Eagleplatform::Record.find(1234)
|
|
144
|
+
# record.delete
|
|
145
|
+
# @return [String] 'Record id: #{id}, name:#{self.name} is deleted' if record deleted successfully
|
|
146
|
+
def delete
|
|
147
|
+
api_method = {method: Methods::RECORD_DELETE[:method],
|
|
148
|
+
path: Methods::RECORD_DELETE[:path].gsub(':id',id.to_s)}
|
|
149
|
+
Eagleplatform.call_api(api_method) == "ok" ? "Record id: '#{self.id}', name:#{self.name} is deleted" : (raise "Can't delete record")
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
##
|
|
153
|
+
# Get all records statistics
|
|
154
|
+
# Date format is - 'dd.mm.yyyy'
|
|
155
|
+
# @option args [String] :date_from ('yesterday') yesterday date
|
|
156
|
+
# @option args [String] :date_to ('today') today date
|
|
157
|
+
# @option args [String] :uniq ('false') unique user statistics
|
|
158
|
+
# @example
|
|
159
|
+
# DATE_FROMAT: 'dd.mm.yyyy'
|
|
160
|
+
# Eagleplatform::Record.statistics(date_from: '1.5.2012', date_to: '25.5.2012', uniq: 'true')
|
|
161
|
+
# @return [Array] return records statistics
|
|
162
|
+
def self.statistics(args = {})
|
|
163
|
+
params = {
|
|
164
|
+
date_from: args[:date_from] || (Time.now - 1.day).strftime('%d.%m.%Y'),
|
|
165
|
+
date_to: args[:date_to] || Time.now.strftime('%d.%m.%Y')
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
raise ArgumentError, "Wrong 'date_from' format. Must be 'dd.mm.yyyy'" unless DATE_FORMAT =~ params[:date_from]
|
|
169
|
+
raise ArgumentError, "Wrong 'date_to' format. Must be 'dd.mm.yyyy'" unless DATE_FORMAT =~ params[:date_from]
|
|
170
|
+
raise ArgumentError, "date_from: #{params[:date_from]} > date_to: #{params[:date_from]}" \
|
|
171
|
+
if params[:date_from].to_date > params[:date_to].to_date
|
|
172
|
+
|
|
173
|
+
params[:uniq] = 'true' if args[:uniq] == true
|
|
174
|
+
result = Eagleplatform.call_api(Methods::RECORDS_GET_STATISTICS, params).first[1]
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
##
|
|
179
|
+
# Get current record statistics
|
|
180
|
+
# Date format is - 'dd.mm.yyyy'
|
|
181
|
+
# @param [Hash] args the statistics options
|
|
182
|
+
# @option args [String] :date_from ('yesterday') yesterday date
|
|
183
|
+
# @option args [String] :date_to ('today') today date
|
|
184
|
+
# @option args [String] :uniq ('false') unique user statistics
|
|
185
|
+
# @example
|
|
186
|
+
# record = Eagleplatform::Record.find(12345)
|
|
187
|
+
# record.statistics(date_from: '1.5.2012', date_to: '25.5.2012')
|
|
188
|
+
# @return [Array] return record statistics
|
|
189
|
+
def statistics(args = {})
|
|
190
|
+
raise "self.id is blank" if self.id.blank?
|
|
191
|
+
params = {
|
|
192
|
+
date_from: args[:date_from] || (Time.now - 1.day).strftime('%d.%m.%Y'),
|
|
193
|
+
date_to: args[:date_to] || Time.now.strftime('%d.%m.%Y')
|
|
194
|
+
}
|
|
195
|
+
params[:uniq] = 'true' if args[:uniq] == true
|
|
196
|
+
|
|
197
|
+
raise ArgumentError, "Wrong 'date_from' format. Must be 'dd.mm.yyyy'" unless DATE_FORMAT =~ params[:date_from]
|
|
198
|
+
raise ArgumentError, "Wrong 'date_to' format. Must be 'dd.mm.yyyy'" unless DATE_FORMAT =~ params[:date_from]
|
|
199
|
+
raise ArgumentError, "date_from: #{params[:date_from]} > date_to: #{params[:date_from]}" \
|
|
200
|
+
if params[:date_from].to_date > params[:date_to].to_date
|
|
201
|
+
|
|
202
|
+
api_method = {method: Methods::RECORD_GET_STATISTICS[:method],
|
|
203
|
+
path: Methods::RECORD_GET_STATISTICS[:path].gsub(':id',id.to_s)}
|
|
204
|
+
result = Eagleplatform.call_api(api_method, params).first[1]
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|