voys_api 0.2.4 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,7 @@ require 'active_support/core_ext/object/try'
8
8
  class VoysApi::Client
9
9
 
10
10
  VOYS_HOST = 'mijn.voys.nl'
11
+ VOYS_DATE_FORMAT = "%m-%d-%Y"
11
12
 
12
13
  def initialize(username, password)
13
14
  @username = username
@@ -49,7 +50,7 @@ class VoysApi::Client
49
50
 
50
51
  options = convert_options(options)
51
52
 
52
- result = agent.post('/cdr/export', options)
53
+ result = agent.get('/cdr/export', options)
53
54
  result.body
54
55
  end
55
56
 
@@ -91,8 +92,10 @@ class VoysApi::Client
91
92
  if recording
92
93
  time = Time.parse(result[:date])
93
94
  recording_filename = "recordings/#{time.strftime("%Y%m%d_%H%M")}-#{source}-#{destination}.wav"
94
- FileUtils.mkdir_p(File.dirname(recording_filename))
95
- get_recording(recording, recording_filename)
95
+ if not File.exists?(recording_filename)
96
+ FileUtils.mkdir_p(File.dirname(recording_filename))
97
+ get_recording(recording, recording_filename)
98
+ end
96
99
  end
97
100
 
98
101
  results << result
@@ -108,7 +111,7 @@ class VoysApi::Client
108
111
  if recording_path =~ /(\d+)\/?$/
109
112
  recording_id = $1
110
113
  filename ||= "#{recording_id}.wav"
111
- agent.get(recording_path).save(filename)
114
+ agent.get(recording_path).save(filename) if not File.exists?(File.join(recording_path, filename))
112
115
  return filename
113
116
  end
114
117
  end
@@ -134,9 +137,20 @@ private
134
137
  def convert_options(options)
135
138
  converted_options = options.clone # deep clone?
136
139
 
140
+ # We need options otherwise other options don't work..
141
+ converted_options = {
142
+ period_from: '',
143
+ period_to: '',
144
+ inboundoutbound: 0,
145
+ totals: 0,
146
+ aggregation: 0,
147
+ recordings: 0,
148
+ page: ''
149
+ }.merge(converted_options) if not converted_options.empty?
150
+
137
151
  # convert options
138
- converted_options[:period_from] = options[:period_from].strftime("%Y-%m-%d") if options[:period_from] && !options[:period_from].is_a?(String)
139
- converted_options[:period_to] = options[:period_to].strftime("%Y-%m-%d") if options[:period_to] && !options[:period_to].is_a?(String)
152
+ converted_options[:period_from] = options[:period_from].strftime(VOYS_DATE_FORMAT) if options[:period_from] && !options[:period_from].is_a?(String)
153
+ converted_options[:period_to] = options[:period_to].strftime(VOYS_DATE_FORMAT) if options[:period_to] && !options[:period_to].is_a?(String)
140
154
 
141
155
  return converted_options
142
156
  end
@@ -1,3 +1,3 @@
1
1
  module VoysApi
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voys_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-05 00:00:00.000000000 Z
12
+ date: 2014-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler