kraken-io 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kraken-io.rb +74 -29
- metadata +50 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcf2758e91edc0914df8ac3b0612094a0acd7afa
|
4
|
+
data.tar.gz: 2d86b7c78d74482902a62682c6c7964c18c32a1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c58c080015aca348f142087ec49b33aa138fc912be1820e64993c22887f8e26c5db84d2485609accb458bf643a8cad62fc9c1ad9af8f70958f108456afde0fe
|
7
|
+
data.tar.gz: f55daf3c1f69dece0381e434089160141fe3c60f25c6c71b933ad28bb511fd3b818b5103c50dd035eb9cdcb409526561e1f8d3283808c7895293ffb026430527
|
data/lib/kraken-io.rb
CHANGED
@@ -1,51 +1,96 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'httparty'
|
3
|
-
require '
|
4
|
-
require '
|
3
|
+
require 'active_support/hash_with_indifferent_access'
|
4
|
+
require 'active_support/core_ext/hash'
|
5
|
+
require 'thread'
|
6
|
+
|
7
|
+
require 'kraken-io/http_multi_part'
|
8
|
+
require 'kraken-io/response'
|
5
9
|
|
6
10
|
module Kraken
|
7
11
|
class API
|
8
12
|
include HTTParty
|
13
|
+
extend HTTPMultiPart
|
14
|
+
|
15
|
+
base_uri 'https://api.kraken.io/v1'
|
9
16
|
|
10
17
|
attr_accessor :api_key, :api_secret
|
11
18
|
|
12
|
-
def initialize(
|
13
|
-
@api_key
|
14
|
-
@api_secret = api_secret
|
19
|
+
def initialize(options = {})
|
20
|
+
@api_key = options.fetch(:api_key)
|
21
|
+
@api_secret = options.fetch(:api_secret)
|
15
22
|
end
|
16
23
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
'api_secret' => @api_secret
|
22
|
-
}
|
23
|
-
})
|
24
|
+
def async
|
25
|
+
@async = true
|
26
|
+
self
|
27
|
+
end
|
24
28
|
|
25
|
-
|
29
|
+
def sync
|
30
|
+
@async = false
|
31
|
+
self
|
26
32
|
end
|
27
33
|
|
28
|
-
def
|
29
|
-
params.merge!(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
def url(url, params = {})
|
35
|
+
params = normalized_params(params).merge!(auth_hash)
|
36
|
+
params[:url] = url
|
37
|
+
call_kraken do
|
38
|
+
res = self.class.post('/url', body: params.to_json)
|
39
|
+
res = Kraken::Response.new(res)
|
40
|
+
yield res if block_given? or return res
|
41
|
+
end
|
42
|
+
end
|
35
43
|
|
36
|
-
|
44
|
+
def callback_url(url)
|
45
|
+
@callback_url = url
|
46
|
+
self
|
47
|
+
end
|
37
48
|
|
38
|
-
|
39
|
-
|
49
|
+
def upload(file_name, params = {})
|
50
|
+
params = normalized_params(params).merge!(auth_hash)
|
51
|
+
call_kraken do
|
52
|
+
res = self.class.multipart_post('/upload', file: file_name, body: params.to_json)
|
53
|
+
res = Kraken::Response.new(res)
|
54
|
+
yield res if block_given? or return res
|
55
|
+
end
|
56
|
+
end
|
40
57
|
|
41
|
-
|
58
|
+
private
|
59
|
+
def call_kraken(&block)
|
60
|
+
if @async
|
61
|
+
call_async(&block)
|
62
|
+
else
|
63
|
+
yield
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def call_async(&block)
|
68
|
+
Thread.abort_on_exception = false
|
69
|
+
Thread.new do |t|
|
70
|
+
block.call
|
71
|
+
end
|
72
|
+
nil
|
73
|
+
end
|
42
74
|
|
43
|
-
|
44
|
-
|
75
|
+
def normalized_params(params)
|
76
|
+
params = params.with_indifferent_access
|
45
77
|
|
46
|
-
|
47
|
-
|
78
|
+
if params.keys.include?(:callback_url) || @callback_url
|
79
|
+
params[:callback_url] = @callback_url
|
80
|
+
else
|
81
|
+
params[:wait] = true
|
48
82
|
end
|
83
|
+
|
84
|
+
params
|
85
|
+
end
|
86
|
+
|
87
|
+
def auth_hash
|
88
|
+
{
|
89
|
+
auth: {
|
90
|
+
api_key: api_key,
|
91
|
+
api_secret: api_secret
|
92
|
+
}
|
93
|
+
}
|
49
94
|
end
|
50
95
|
end
|
51
|
-
end
|
96
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kraken-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Przemek Matylla
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: multipart-post
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - '>='
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: activesupport
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - '>='
|
@@ -67,13 +67,55 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
|
-
type: :
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.17'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.17'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
77
119
|
prerelease: false
|
78
120
|
version_requirements: !ruby/object:Gem::Requirement
|
79
121
|
requirements:
|
@@ -81,7 +123,7 @@ dependencies:
|
|
81
123
|
- !ruby/object:Gem::Version
|
82
124
|
version: '0'
|
83
125
|
description: With this gem you can plug into the power and speed of Kraken.io Image
|
84
|
-
Optimizer.
|
126
|
+
Optimizer. https://kraken.io/
|
85
127
|
email:
|
86
128
|
- przemek@matylla.pl
|
87
129
|
executables: []
|
@@ -109,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
151
|
version: '0'
|
110
152
|
requirements: []
|
111
153
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.0.
|
154
|
+
rubygems_version: 2.0.14
|
113
155
|
signing_key:
|
114
156
|
specification_version: 4
|
115
157
|
summary: Ruby gem for interacting with Kraken.io API
|