linkshare-oauth2-api 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aac148207bf1393583c7c27460a1af0e021d11e5
4
- data.tar.gz: c05c25103577df3ea1ce951202a3bb7ff2b8d9c7
3
+ metadata.gz: 13b9df35964ecdb298c3d5a1c83a075d89d15187
4
+ data.tar.gz: cf05cd12fe2ea068de5be0c1ca0df34338547366
5
5
  SHA512:
6
- metadata.gz: 96b5385aa09d3266e367baad1ac719bd88b4bfe97382da48f86f6e47168f492fdb90fe54ab197040d4a291a919f02edbc6b29192c18b485310643a52d9e388a5
7
- data.tar.gz: 3db764a1ab48bb1b3d882312edba0453fc61bd738ca36448ab14068617f9b2515622339e4b2bc91804ea7613a8ddc08e590ef0c00253b0c40366bc77db1e683b
6
+ metadata.gz: 350ab8f384bfce70f67934931982c18626e95317f766a1ba6d06508ce49f5285680cd5e790901029d01ce6f4ab63ae0af531f2683a2e794b67a9ab0a9565e47e
7
+ data.tar.gz: 1bcebfc2cb2a248562b7ce2403bd6eed1ec4f8cbd8562a64c34c64f102850e9454368d615a0762bfe96a339cd1c076600e7c2ef146f19c8c1a5d50f1233d45a3
@@ -1,4 +1,5 @@
1
1
  require "open-uri"
2
+ require 'csv'
2
3
  module Linkshare
3
4
  class CustomReports
4
5
  def initilize()
@@ -6,9 +7,7 @@ module Linkshare
6
7
  @reportsRows = []
7
8
  @cols = []
8
9
  end
9
- def getCSV
10
- @reportsCSV
11
- end
10
+
12
11
 
13
12
  def getReports
14
13
  @reportsRows
@@ -17,21 +16,22 @@ module Linkshare
17
16
  token = Linkshare.custom_report_token
18
17
  url = Linkshare::API_URIS[:custom_reports]+'/'+reportname+'/filters?start_date='+bdate+'&end_date='+edate+'&include_summary='+include_summary+'&network='+network.to_s+'&tz='+tz+'&date_type='+date_type+'&token='+token
19
18
  @reportsRows = []
20
- @reportsCSV = open(url).read()
21
- reportsrows = @reportsCSV.force_encoding("UTF-8").gsub("\"",'').split(/\n/)
22
- if !reportsrows[1].nil? && reportsrows[1].match(/^\{code\:.*\}$/)
23
- raise 'Linkshare Error (custom report): ' + reportsrows[1]
24
- end
25
- @cols = reportsrows[0].split(/,/)
26
- reportsrows.shift
27
- reportsrows.each { |row|
28
- r = {}
29
- split_row = row.split(/,/)
30
- @cols.each_with_index { | o, i|
31
- r[@cols[i]]=split_row[i]
32
- }
33
- @reportsRows.push(r)
34
- }
19
+
20
+ filename = "linkshare_custom_report_#{reportname}_#{bdate}_#{edate}"
21
+
22
+ path = "#{Rails.root.join('tmp')}/#{filename}.csv"
23
+ file = Tempfile.new(["#{filename}", '.csv'])
24
+ file.binmode
25
+ file << open(url).read
26
+ file.close
27
+
28
+ CSV.open(path, 'w', headers: :first_row, col_sep: ',', row_sep: "\n", encoding: 'utf-8') do |csv|
29
+ CSV.open(file.path, 'r:bom|utf-8', headers: :first_row, col_sep: ',', quote_char: "\"", row_sep: "\n").each_with_index do |line, index|
30
+ @reportsRows.push(line)
31
+
32
+ end
33
+ end
34
+
35
35
  @reportsRows
36
36
  end
37
37
  end
@@ -1,3 +1,3 @@
1
1
  module Linkshare
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linkshare-oauth2-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rudie Shahinian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-03 00:00:00.000000000 Z
11
+ date: 2016-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails