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.
Files changed (55) hide show
  1. data/.autotest +9 -0
  2. data/.gitignore +2 -0
  3. data/.rspec +2 -0
  4. data/.yardoc/checksums +6 -0
  5. data/.yardoc/objects/root.dat +0 -0
  6. data/.yardoc/proxy_types +0 -0
  7. data/doc/.yardoc/checksums +0 -0
  8. data/doc/.yardoc/objects/root.dat +0 -0
  9. data/doc/.yardoc/proxy_types +0 -0
  10. data/doc/Eagleplatform.html +413 -0
  11. data/doc/Eagleplatform/EagleplatformObject.html +224 -0
  12. data/doc/Eagleplatform/Filter.html +1009 -0
  13. data/doc/Eagleplatform/Methods.html +181 -0
  14. data/doc/Eagleplatform/Record.html +1497 -0
  15. data/doc/Eagleplatform/Translation.html +1103 -0
  16. data/doc/Hash.html +210 -0
  17. data/doc/_index.html +157 -0
  18. data/doc/class_list.html +47 -0
  19. data/doc/css/common.css +1 -0
  20. data/doc/css/full_list.css +55 -0
  21. data/doc/css/style.css +322 -0
  22. data/doc/doc/_index.html +84 -0
  23. data/doc/doc/class_list.html +47 -0
  24. data/doc/doc/css/common.css +1 -0
  25. data/doc/doc/css/full_list.css +55 -0
  26. data/doc/doc/css/style.css +322 -0
  27. data/doc/doc/file_list.html +46 -0
  28. data/doc/doc/frames.html +13 -0
  29. data/doc/doc/index.html +84 -0
  30. data/doc/doc/js/app.js +205 -0
  31. data/doc/doc/js/full_list.js +173 -0
  32. data/doc/doc/js/jquery.js +16 -0
  33. data/doc/doc/method_list.html +46 -0
  34. data/doc/doc/top-level-namespace.html +95 -0
  35. data/doc/file_list.html +46 -0
  36. data/doc/frames.html +13 -0
  37. data/doc/index.html +157 -0
  38. data/doc/js/app.js +205 -0
  39. data/doc/js/full_list.js +173 -0
  40. data/doc/js/jquery.js +16 -0
  41. data/doc/method_list.html +262 -0
  42. data/doc/top-level-namespace.html +105 -0
  43. data/eagleplatform.gemspec +22 -0
  44. data/eagleplatform.tmproj +138 -0
  45. data/lib/.yardoc/checksums +1 -0
  46. data/lib/.yardoc/objects/root.dat +0 -0
  47. data/lib/.yardoc/proxy_types +0 -0
  48. data/lib/eagleplatform.rb +135 -0
  49. data/lib/eagleplatform/eagleplatform_object.rb +10 -0
  50. data/lib/eagleplatform/filter.rb +125 -0
  51. data/lib/eagleplatform/record.rb +207 -0
  52. data/lib/eagleplatform/translation.rb +163 -0
  53. data/lib/eagleplatform/version.rb +3 -0
  54. data/spec/eagleplatform_spec.rb +146 -0
  55. metadata +135 -0
@@ -0,0 +1,163 @@
1
+ module Eagleplatform
2
+ # Translations
3
+ class Translation < EagleplatformObject.new(:id, :name, :description, :status, :announce, :created_at,
4
+ :updated_at, :starts_at, :ad_template_id, :product_code,
5
+ :age_restrictions_type, :country_access_template_id,
6
+ :player_template_id, :site_access_template_id, :stream_name,
7
+ :announce, :account_id, :user_id)
8
+
9
+ undef user_id=
10
+ undef account_id=
11
+ undef status=
12
+ undef created_at=
13
+ undef updated_at=
14
+ undef starts_at=
15
+
16
+ ##
17
+ # Get list of translations
18
+ # @param [Numeric] per_page translations number per page
19
+ # @param [Numeric] page translations page
20
+ # @example
21
+ # translations = Eagleplatform::Translation.list
22
+ #
23
+ # #Get translations page=2, per_page=20
24
+ # translations = Eagleplatform::Translation.list(20,2)
25
+ # @return [Array] Array of Translations objects
26
+ def self.list(per_page = 50, page = 1)
27
+ params = {
28
+ per_page: per_page.to_s,
29
+ page: page.to_s
30
+ }
31
+ result = Eagleplatform.call_api(Methods::TRANSLATIONS_GET_LIST, params).to_options
32
+ translations = []
33
+ result[:translations].each do |translation|
34
+ t = self.new
35
+ t.each_pair { |k,v| t[k] = translation[k.to_s]}
36
+ translations.push(t)
37
+ end
38
+ if result[:total_pages] > 1
39
+ puts "Translations per_page: #{per_page}"
40
+ puts "Current page: #{result[:current_page]}"
41
+ puts "Total pages: #{result[:total_pages]}"
42
+ puts "Total entries: #{result[:total_entries]}"
43
+ end
44
+ translations
45
+ end
46
+
47
+
48
+ ##
49
+ # Find Translation by ID
50
+ # @param [Numeric] id ID of translation
51
+ # @example
52
+ # Eagleplatform::Translation.find(45632)
53
+ # @return [Eagleplaform::Translation] if translation present
54
+ # @raise [ArgumentError] id must be numeric
55
+ def self.find(id)
56
+ raise ArgumentError, "id must be numeric" unless id.is_a? Numeric
57
+ api_method = {method: Methods::TRANSLATION_GET_INFO[:method],
58
+ path: Methods::TRANSLATION_GET_INFO[:path].gsub(':id',id.to_s)}
59
+
60
+ result = Eagleplatform.call_api(api_method).first[1].to_options
61
+ trans = self.new
62
+ trans.each_pair { |k,v| trans[k] = result[k] }
63
+ end
64
+
65
+
66
+ ##
67
+ # Update translation on Eagleplatform
68
+ # @param [Hash] translation Hash of translation fields
69
+ # @option translation [String] :id
70
+ # @option translation [String] :name
71
+ # @option translation [String] :description
72
+ # @example
73
+ # Eagleplatform::Translation.update(id: 1234, name: 'Hello world', description: 'Heyy')
74
+ # @return [Hash] Updated translation
75
+ def self.update(args = {})
76
+ raise ArgumentError, 'ID is blank' if args[:id].blank?
77
+ raise ArgumentError, 'id must be numeric' unless args[:id].is_a? Numeric
78
+ params = {
79
+ translation: args
80
+ }
81
+
82
+ api_method = {method: Methods::TRANSLATION_UPDATE[:method],
83
+ path: Methods::TRANSLATION_UPDATE[:path].gsub(':id',args[:id].to_s)}
84
+ result = Eagleplatform.call_api(api_method, params).first[1].to_options
85
+ end
86
+
87
+
88
+ ##
89
+ # Delete translation from Eagleplatform
90
+ # @example
91
+ # Eagleplatform::Translation.delete(1234)
92
+ # @return [String] 'Translation id: #{id} is deleted' if translation deleted successfully
93
+ def self.delete(id)
94
+ raise ArgumentError, 'id must be numeric' unless id.is_a? Numeric
95
+ api_method = {method: Methods::TRANSLATION_DELETE[:method],
96
+ path: Methods::TRANSLATION_DELETE[:path].gsub(':id',id.to_s)}
97
+ Eagleplatform.call_api(api_method) == "ok" ? "Translation id: '#{id}' is switched off" : (raise "Can't switch off translation")
98
+ end
99
+
100
+
101
+ ##
102
+ # Update translation on Eagleplatform
103
+ # @example
104
+ # t = Eagleplatform::Translation.find(1234)
105
+ # t.description = 'Mega stream'
106
+ # t.update
107
+ # @return [Eagleplatform::Translation] if record successfully updated
108
+ def update
109
+ api_method = {method: Methods::TRANSLATION_UPDATE[:method],
110
+ path: Methods::TRANSLATION_UPDATE[:path].gsub(':id',id.to_s)}
111
+ params = {}
112
+ translation = self.to_hash
113
+ translation.delete(:user_id)
114
+ translation.delete(:account_id)
115
+ translation.delete(:status)
116
+ translation.delete(:created_at)
117
+ translation.delete(:updated_at)
118
+ translation.delete(:starts_at)
119
+
120
+ params[:translation] = translation
121
+ result = Eagleplatform.call_api(api_method, params).first[1].to_options
122
+ translation.diff(result).keys.include?(:updated_at) ? self : 'Something wrong'
123
+ end
124
+
125
+ ##
126
+ # Switch off translation from Eagleplaform
127
+ # @example
128
+ # t = Eagleplatform::translation.find(1234)
129
+ # t.delete
130
+ # @return [String] 'ok' if translation switched off successfully
131
+ def delete
132
+ api_method = {method: Methods::TRANSLATION_DELETE[:method],
133
+ path: Methods::TRANSLATION_DELETE[:path].gsub(':id',id.to_s)}
134
+ Eagleplatform.call_api(api_method) == "ok" ? "Translation id: '#{self.id}', name:#{self.name} is switched off" : (raise "Can't switch off translation")
135
+ end
136
+
137
+ ##
138
+ # Get current translation statistics
139
+ # Date format is - 'dd.mm.yyyy'
140
+ # @param [Hash] args the statistics options
141
+ # @option args [String] :date_from ('yesterday') yesterday date
142
+ # @option args [String] :date_to ('today') today date
143
+ # @example
144
+ # t = Eagleplatform::Translation.find(12345)
145
+ # t.statistics(date_from: '1.5.2012', date_to: '25.5.2012')
146
+ # @return [Array] return translation statistics
147
+ def statistics(args = {})
148
+ raise "self.id is blank" if self.id.blank?
149
+ params = {
150
+ date_from: args[:date_from] || (Time.now - 1.day).strftime('%d.%m.%Y'),
151
+ date_to: args[:date_to] || Time.now.strftime('%d.%m.%Y')
152
+ }
153
+
154
+ raise ArgumentError, "Wrong 'date_from' format. Must be 'dd.mm.yyyy'" unless DATE_FORMAT =~ params[:date_from]
155
+ raise ArgumentError, "Wrong 'date_to' format. Must be 'dd.mm.yyyy'" unless DATE_FORMAT =~ params[:date_from]
156
+ raise ArgumentError, "date_from: #{params[:date_from]} > date_to: #{params[:date_from]}" if params[:date_from].to_date > params[:date_to].to_date
157
+
158
+ api_method = {method: Methods::TRANSLATION_GET_STATISTICS[:method],
159
+ path: Methods::TRANSLATION_GET_STATISTICS[:path].gsub(':id',id.to_s)}
160
+ result = Eagleplatform.call_api(api_method, params).first[1]
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,3 @@
1
+ module Eagleplatform
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,146 @@
1
+ require File.dirname(__FILE__) + '/../lib/eagleplatform.rb'
2
+
3
+ describe "Eaglepltaform" do
4
+ it "methods list" do
5
+ Eagleplatform::Methods.constants should_not be nil
6
+ end
7
+
8
+ describe "setup" do
9
+ it 'should raise ArgumentError if params < 2' do
10
+ lambda { Eagleplatform.sutup }.should raise_error
11
+ end
12
+
13
+ it 'should raise ArgumenError "account is blank" if account is blank' do
14
+ lambda { Eagleplatform.setup('','foo') }.should raise_error(ArgumentError, 'account is blank')
15
+ end
16
+
17
+ it 'should raise ArgumentError "auth_token is blank" if auth_token is blank' do
18
+ lambda { Eagleplatform.setup('foo','') }.should raise_error(ArgumentError, 'auth_token is blank')
19
+ end
20
+
21
+ it 'should raise ArgumentError "server is blank" if serevr is blank ' do
22
+ lambda { Eagleplatform.setup('foo','bar', '') }.should raise_error(ArgumentError, 'server is blank')
23
+ end
24
+
25
+ it "should slice! 'http://' from server if it present" do
26
+ Eagleplatform.setup('foo','bar', 'http://www.example.com')
27
+ Eagleplatform.module_eval('@@api_url.to_s').should == 'http://www.example.com'
28
+ end
29
+ end
30
+
31
+ describe 'request' do
32
+ it 'should raise ArgumentError without parameters' do
33
+ lambda { Eagleplatform.request }.should raise_error(ArgumentError)
34
+ end
35
+
36
+ it 'should raise error "You must set account" if @@account is nil' do
37
+ Eagleplatform.module_eval('@@account = nil')
38
+ lambda { Eagleplatform.request({method: 'put', path: '/root'})}.should raise_error('You must set account')
39
+ end
40
+
41
+ it 'should raise error "You must set auth_token" if @@account is nil' do
42
+ Eagleplatform.module_eval("@@account = 'sa'; @@auth_token = nil")
43
+ lambda { Eagleplatform.request({method: 'put', path: '/root'})}.should raise_error('You must set auth_token')
44
+ end
45
+
46
+ it 'should raise error if api_method[:method] or api_method[:path] is blank' do
47
+ Eagleplatform.module_eval("@@account = 'foo'; @@auth_token = 'bar'")
48
+ lambda { Eagleplatform.request({method: '', path: ''}) }.should raise_error("Wrong api_method param")
49
+ end
50
+
51
+ it "should raise error if api_method[:method] not one of get, post, put, delete" do
52
+ Eagleplatform.module_eval("@@account = 'foo'; @@auth_token = 'bar'")
53
+ lambda { Eagleplatform.request({method: 'wrong_method', path: '/path'}) }.should raise_error("Wrong http method name 'wrong_method'")
54
+ end
55
+ end
56
+
57
+ context 'Record' do
58
+ describe "self.find" do
59
+ it 'should raise ArgumentError without parameters' do
60
+ lambda { Eagleplatform::Record.find }.should raise_error(ArgumentError)
61
+ end
62
+
63
+ it "should raise ArgumentError 'id must be numeric' if id is not numeric" do
64
+ lambda { Eagleplatform::Record.find('not_numeric') }.should raise_error(ArgumentError,"id must be numeric")
65
+ end
66
+
67
+ it "should return Record Object" do
68
+ # record = { record: {
69
+ # id: 47030,
70
+ # name: "test",
71
+ # description: '',
72
+ # duration: 4307190,
73
+ # origin: "http://eagle.b25.servers.eaglecdn.com/20120517/4fb50297b0b6f.flv",
74
+ # origin_size: 115810695,
75
+ # is_processed: true,
76
+ # screenshot: "http://st1.eaglecdn.com/eagle/20120517/4fb50297b0b6f_362_640x360.jpg",
77
+ # view_count: 0,
78
+ # click_url: "http://ya.ru?47030",
79
+ # user_id: 26,
80
+ # recorded_at: '',
81
+ # updated_at: "2012-05-17T13:53:17+00:00",
82
+ # created_at: "2012-05-17T13:52:28+00:00"
83
+ # }
84
+ # }
85
+ # Eagleplatform.stub!(:call_api).and_return(record)
86
+ # Eagleplatform::Record.find(47030).should be_an_instance_of Eagleplatform::Record
87
+ end
88
+ end
89
+
90
+ describe "self.upload_from_ftp" do
91
+ it "should raise ArgumentError if record[:name] is blank" do
92
+ lambda { Eagleplatform::Record.upload_from_ftp( record: {name: ''})}.
93
+ should raise_error(ArgumentError,"record[:name] is blank")
94
+ end
95
+
96
+ it "should raise ArgumentError if ftp[:server] is blank" do
97
+ lambda { Eagleplatform::Record.upload_from_ftp( record: {name: 'foo'},
98
+ ftp: { server: ''}) }.should raise_error(ArgumentError,"ftp[:server] is blank")
99
+ end
100
+
101
+ it "should raise ArgumentError if ftp[:file_path] is blank" do
102
+ lambda { Eagleplatform::Record.upload_from_ftp( record: {name: 'foo'},
103
+ ftp: { server: 'bar', file_path: ''}) }.should raise_error(ArgumentError,"ftp[:file_path] is blank")
104
+ end
105
+ end
106
+
107
+ describe "self.upload_from_http" do
108
+ it "should raise ArgumentError if record[:name] is blank" do
109
+ lambda { Eagleplatform::Record.upload_from_http( record: {name: ''})}.
110
+ should raise_error(ArgumentError,"record[:name] is blank")
111
+ end
112
+
113
+ it "should raise ArgumentError if 'upload_url' is blank" do
114
+ lambda { Eagleplatform::Record.upload_from_http( record: {name: 'foo'},
115
+ upload_url: '')}.should raise_error(ArgumentError,"upload_url is blank")
116
+ end
117
+ end
118
+
119
+
120
+ describe "update" do
121
+
122
+ end
123
+
124
+ describe "delete" do
125
+
126
+ end
127
+
128
+ describe "self.statistics" do
129
+ it "should raise ArgumentError if wrong date format" do
130
+ lambda { Eagleplatform::Record.statistics(date_from: '11,2.2001') }.should raise_error(ArgumentError)
131
+ end
132
+
133
+ it "should raise ArgumentError if date_from > date_to" do
134
+ lambda { Eagleplatform::Record.statistics(date_from: '11.2.2012', date_to: '1.2.2010') }.should raise_error(ArgumentError)
135
+ end
136
+ end
137
+
138
+ describe "statistics" do
139
+ it "should raise Error if self.id is blank" do
140
+ end
141
+ end
142
+ end
143
+
144
+ end
145
+
146
+
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eagleplatform
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vachagan Gevorkyan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: ! 'Eagleplatform API library for crud records, translations etc. For
47
+ more infromation see documentation '
48
+ email:
49
+ - va4@deultonmedia.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .autotest
55
+ - .gitignore
56
+ - .rspec
57
+ - .yardoc/checksums
58
+ - .yardoc/objects/root.dat
59
+ - .yardoc/proxy_types
60
+ - doc/.DS_Store
61
+ - doc/.yardoc/checksums
62
+ - doc/.yardoc/objects/root.dat
63
+ - doc/.yardoc/proxy_types
64
+ - doc/Eagleplatform.html
65
+ - doc/Eagleplatform/EagleplatformObject.html
66
+ - doc/Eagleplatform/Filter.html
67
+ - doc/Eagleplatform/Methods.html
68
+ - doc/Eagleplatform/Record.html
69
+ - doc/Eagleplatform/Translation.html
70
+ - doc/Hash.html
71
+ - doc/_index.html
72
+ - doc/class_list.html
73
+ - doc/css/common.css
74
+ - doc/css/full_list.css
75
+ - doc/css/style.css
76
+ - doc/doc/_index.html
77
+ - doc/doc/class_list.html
78
+ - doc/doc/css/common.css
79
+ - doc/doc/css/full_list.css
80
+ - doc/doc/css/style.css
81
+ - doc/doc/file_list.html
82
+ - doc/doc/frames.html
83
+ - doc/doc/index.html
84
+ - doc/doc/js/app.js
85
+ - doc/doc/js/full_list.js
86
+ - doc/doc/js/jquery.js
87
+ - doc/doc/method_list.html
88
+ - doc/doc/top-level-namespace.html
89
+ - doc/file_list.html
90
+ - doc/frames.html
91
+ - doc/index.html
92
+ - doc/js/app.js
93
+ - doc/js/full_list.js
94
+ - doc/js/jquery.js
95
+ - doc/method_list.html
96
+ - doc/top-level-namespace.html
97
+ - eagleplatform.gemspec
98
+ - eagleplatform.tmproj
99
+ - lib/.yardoc/checksums
100
+ - lib/.yardoc/objects/root.dat
101
+ - lib/.yardoc/proxy_types
102
+ - lib/eagleplatform.rb
103
+ - lib/eagleplatform/eagleplatform_object.rb
104
+ - lib/eagleplatform/filter.rb
105
+ - lib/eagleplatform/record.rb
106
+ - lib/eagleplatform/translation.rb
107
+ - lib/eagleplatform/version.rb
108
+ - spec/eagleplatform_spec.rb
109
+ homepage: http://www.eagleplatform.com
110
+ licenses: []
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project: eagleplatform
129
+ rubygems_version: 1.8.21
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Eagleplatform API library
133
+ test_files:
134
+ - spec/eagleplatform_spec.rb
135
+ has_rdoc: