wrike3 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6730c885c7485faeecd911bd9507eca5ec2e4e78
4
- data.tar.gz: 19a45be13b7f254c1a4b8ebed370528f85ce2ac4
3
+ metadata.gz: f54978dd72a534d731f5c74636aa7816fd372c56
4
+ data.tar.gz: fa1346a2bc9d1ac028f2e991f8d7d9082ce2168e
5
5
  SHA512:
6
- metadata.gz: 521c81c0174a56a342009fe6435fcdd763d80aaf452d02a9c1fd498dea8bb991a7cb9c8e1234e08373c209a29a02466ac16af78a2a1b69fbc88478cd1d36548d
7
- data.tar.gz: 728d95421482246b203150fb287d0e33d0b89353439f3f34dde13e6d91e640e046d8ea406ea83b793c455d5d6ffeceab8ef76413b954dd4f1807fa30535fa817
6
+ metadata.gz: 1cb4dd8c87a3e8844cce1058c996b3005fb702ab99213b4c3dcbba1f25ac6c7ba4ec75ca968a17dabc8e87a110aaef1968e5d23be9b3dd12971b01786b194a05
7
+ data.tar.gz: e7d1b27a6da9d2acfd5d4873acb7e39163ce09bdd424e2ed32c8bfae7807bd04eef0cc858567cc430d8b263c9a2b0282df93af93672ad7ee9209243e050ee2d5
@@ -4,7 +4,6 @@ require 'mime/types'
4
4
 
5
5
  require 'wrike3/error'
6
6
  require 'wrike3/common'
7
- require 'wrike3/utils'
8
7
 
9
8
  require 'wrike3/base'
10
9
  require 'wrike3/token'
@@ -1,6 +1,9 @@
1
+ require 'open-uri'
2
+
1
3
  module Wrike3
2
4
  class Attachment
3
5
  include Wrike3::Common
6
+ CRLF = "\r\n"
4
7
 
5
8
  def initialize(wrike)
6
9
  @wrike = wrike
@@ -14,11 +17,11 @@ module Wrike3
14
17
  def details(id, params = {})
15
18
  wrike.execute(:get, api_url("attachments/#{id}"), params)
16
19
  end
17
-
20
+
18
21
  # Upload attachment for specified task
19
- def upload(attachable_type, attachable_id, stream)
20
- body, headers = http_multipart_data({:stream => stream})
21
- wrike.execute(:post, api_url(nested_path('attachments', attachable_type, attachable_id)), body, headers)
22
+ def upload(attachable_type, attachable_id, params)
23
+ body, headers = http_multipart_data(params)
24
+ wrike.execute(:post, api_url(nested_path('attachments', attachable_type, attachable_id)), {}, headers, true, body)
22
25
  end
23
26
 
24
27
  # Get file binary stream
@@ -30,5 +33,17 @@ module Wrike3
30
33
  def delete(id, params = {})
31
34
  wrike.execute(:delete, api_url("attachments/#{id}"), params)
32
35
  end
36
+
37
+ private
38
+
39
+ def http_multipart_data(params = {})
40
+ headers = {
41
+ 'X-Requested-With' => 'XMLHttpRequest',
42
+ 'X-File-Name' => params['file_name'],
43
+ 'Content-Type' => params['content_type']
44
+ }
45
+
46
+ return params['stream'], headers
47
+ end
33
48
  end
34
- end
49
+ end
@@ -2,9 +2,9 @@ module Wrike3
2
2
  class Base
3
3
  def initialize(options={})
4
4
  # API settings
5
- Wrike3.api_version = options.fetch(:api_version) { 'v3' }
6
- Wrike3.protocol = options.fetch(:protocol) { 'https' }
7
- Wrike3.api_host = options.fetch(:api_host) { 'www.wrike.com' }
5
+ Wrike3.api_version = options.fetch(:api_version) { 'v3' }
6
+ Wrike3.protocol = options.fetch(:protocol) { 'https' }
7
+ Wrike3.api_host = options.fetch(:api_host) { 'www.wrike.com' }
8
8
  # Access settings
9
9
  Wrike3.access_token = options.fetch(:access_token) { '' }
10
10
  end
@@ -58,9 +58,12 @@ module Wrike3
58
58
  @token ||= Wrike3::Token.new(self)
59
59
  end
60
60
 
61
- def execute(method, url, parameters = {}, request_headers = {}, include_auth_header = true)
61
+ def execute(method, url, parameters = {}, request_headers = {}, include_auth_header = true, body = nil)
62
62
  request_headers = auth_headers(request_headers) if include_auth_header
63
- response = HTTParty.send(method.to_s, url, {:query => to_j(parameters), headers: request_headers})
63
+ params = {:query => to_j(parameters), headers: request_headers}
64
+ params[:body] = body if body.present?
65
+
66
+ response = HTTParty.send(method.to_s, url, params)
64
67
  response.parsed_response
65
68
  end
66
69
 
@@ -12,15 +12,5 @@ module Wrike3
12
12
  path = "#{type}/#{id}/#{path}" if type.present? && id.present?
13
13
  path
14
14
  end
15
-
16
- def to_j(parameters = {})
17
- parameters.each do |item|
18
- if item.last.is_a?(Hash) || item.last.is_a?(Array)
19
- parameters[item.first.to_s] = item.last.to_json
20
- end
21
- end
22
-
23
- parameters
24
- end
25
15
  end
26
16
  end
@@ -1,3 +1,3 @@
1
1
  module Wrike3
2
- VERSION = '0.3.5'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.rubygems_version = '1.9.3'
25
25
 
26
26
  s.add_runtime_dependency('httparty', '~> 0.13.7')
27
- s.add_runtime_dependency('mime-types', '~> 2.99', '>= 2.99.1')
27
+ s.add_runtime_dependency('mime-types')
28
28
  s.add_runtime_dependency('shoulda', '~> 3.5')
29
29
  s.add_runtime_dependency('mocha', '~> 1.1')
30
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrike3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morshed Alam
@@ -28,22 +28,16 @@ dependencies:
28
28
  name: mime-types
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.99'
34
31
  - - ">="
35
32
  - !ruby/object:Gem::Version
36
- version: 2.99.1
33
+ version: '0'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '2.99'
44
38
  - - ">="
45
39
  - !ruby/object:Gem::Version
46
- version: 2.99.1
40
+ version: '0'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: shoulda
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +92,6 @@ files:
98
92
  - lib/wrike3/timelog.rb
99
93
  - lib/wrike3/token.rb
100
94
  - lib/wrike3/user.rb
101
- - lib/wrike3/utils.rb
102
95
  - lib/wrike3/version.rb
103
96
  - lib/wrike3/workflow.rb
104
97
  - test/.DS_Store
@@ -1,33 +0,0 @@
1
- module Wrike3
2
- class Helper
3
- CRLF = "\r\n"
4
-
5
- class << self
6
- def http_multipart_data(params)
7
- body = ''
8
- headers = {}
9
- boundary = Time.now.to_i.to_s(16)
10
- headers["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
11
-
12
- # params.each do |key, value|
13
- # esc_key = OAuth::Helper.escape(key.to_s)
14
- # body << "--#{boundary}#{CRLF}"
15
- #
16
- # if value.respond_to?(:read)
17
- # mime_type = MIME::Types.type_for(value.path)[0] || MIME::Types["application/octet-stream"][0]
18
- # body << "Content-Disposition: form-data; name=\"#{esc_key}\"; filename=\"#{File.basename(value.path)}\"#{CRLF}"
19
- # body << "Content-Type: #{mime_type.simplified}#{CRLF*2}"
20
- # body << value.read
21
- # else
22
- # body << "Content-Disposition: form-data; name=\"#{esc_key}\"#{CRLF*2}#{value}"
23
- # end
24
- # end
25
-
26
- body << "--#{boundary}--#{CRLF*2}"
27
- headers["Content-Length"] = body.size.to_s
28
-
29
- return [body, headers]
30
- end
31
- end
32
- end
33
- end