6px 0.0.1 → 1.0.0
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 +4 -4
- data/lib/6px.rb +1 -1
- data/lib/6px/client.rb +106 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a24925555b5af31ab2a95c19b40b3cacda0f529
|
4
|
+
data.tar.gz: 0691e0b3027586c2945ce2336cd21422f1ef3995
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42d6211294c698e54ac9f7d213cecf771ec9436d1d606f75ba0edf3c779883b4e38292c9b5390ea3b7c8361692aa4a457305b09e24cb57b79b0fde61a9df4f95
|
7
|
+
data.tar.gz: dc25ebd34888fffe67ab132357bbe08e794da547619216acf118c3b16d1dd7803e03ef59ce166a8e960a55e2bc5b52b42c5724b2bc5e3e4b23e6d1f833fe7d9b
|
data/lib/6px.rb
CHANGED
data/lib/6px/client.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
|
1
|
+
require 'json'
|
2
2
|
|
3
|
+
class SixPX
|
3
4
|
include HTTParty
|
4
5
|
|
6
|
+
METHOD_NAMES = [:rotate, :resize, :crop, :filter, :layer, :analyze]
|
7
|
+
|
5
8
|
base_uri 'https://api.6px.io/v1/'
|
6
9
|
headers 'Content-Type' => 'application/json'
|
7
10
|
|
@@ -12,39 +15,122 @@ class SixPX
|
|
12
15
|
api_secret = args[:api_secret]
|
13
16
|
self.class.base_uri << "/users/#{user_id}/"
|
14
17
|
self.class.default_params key: api_key, secret: api_secret
|
18
|
+
@payload = {}
|
19
|
+
@inputs = {}
|
20
|
+
@methods = []
|
21
|
+
@refs = {}
|
22
|
+
@type = 'jpeg'
|
23
|
+
@url = ''
|
24
|
+
@data = {}
|
25
|
+
@callback = ''
|
15
26
|
end
|
16
27
|
|
17
|
-
|
28
|
+
# For querying what jobs have been submitted
|
18
29
|
def jobs(*query)
|
19
|
-
|
20
|
-
|
21
|
-
|
30
|
+
query = query.first
|
31
|
+
job_id = query.delete(:job_id) if query
|
32
|
+
url = job_id ? "jobs/#{job_id}" : "jobs"
|
33
|
+
query = clean_up_search_params(query)
|
34
|
+
response = self.class.get(url, query: query).body
|
35
|
+
JSON.parse(response)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Sets images to that need to be processed
|
39
|
+
def inputs(inputs)
|
40
|
+
@inputs = inputs
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
# Add whichs images to process
|
45
|
+
def refs(refs)
|
46
|
+
@refs = refs
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
# Sets what type the output should be in. Default is jpeg.
|
51
|
+
def type(type)
|
52
|
+
@type = type
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
# Sets output url
|
57
|
+
def url(url)
|
58
|
+
@url = url
|
59
|
+
self
|
22
60
|
end
|
23
61
|
|
24
|
-
|
25
|
-
|
62
|
+
# Sets additional data on job
|
63
|
+
def data(data)
|
64
|
+
@data = data
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
# Sets callbacks on job
|
69
|
+
def callback(callback)
|
70
|
+
@callback = callback
|
71
|
+
self
|
72
|
+
end
|
26
73
|
|
27
|
-
|
74
|
+
# Defines all functions for methods
|
75
|
+
METHOD_NAMES.each do |mn|
|
76
|
+
define_method(mn) do |params|
|
77
|
+
add_method(mn.to_s, params)
|
78
|
+
self
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Builds and sends the payload to 6px
|
83
|
+
def send
|
84
|
+
payload = build_payload.to_json
|
85
|
+
empty_variables
|
86
|
+
response = self.class.post("jobs", body: payload).body
|
87
|
+
JSON.parse(response)
|
28
88
|
end
|
29
89
|
|
30
90
|
private
|
31
91
|
|
32
|
-
def
|
92
|
+
def clean_up_search_params(params)
|
93
|
+
parsed_hash = {}
|
94
|
+
params.each {|i,k| parsed_hash[i.to_s.gsub('_', '.')] = k }
|
95
|
+
parsed_hash
|
96
|
+
end
|
97
|
+
|
98
|
+
# Add methods to method hash
|
99
|
+
def add_method(method, options)
|
100
|
+
@methods << {
|
101
|
+
'method' => method,
|
102
|
+
'options' => options
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
# Builds the final payload to send
|
107
|
+
def build_payload
|
33
108
|
{
|
34
|
-
input: inputs,
|
109
|
+
input: @inputs,
|
35
110
|
output: [
|
36
111
|
{
|
37
|
-
methods: methods,
|
38
|
-
type: "image/#{
|
39
|
-
ref:
|
40
|
-
|
41
|
-
'img2' => false,
|
42
|
-
'img3' => false,
|
43
|
-
'img4' => false
|
44
|
-
},
|
45
|
-
url: destination
|
112
|
+
methods: @methods,
|
113
|
+
type: "image/#{@type}",
|
114
|
+
ref: @refs,
|
115
|
+
url: @url
|
46
116
|
}
|
47
|
-
]
|
117
|
+
],
|
118
|
+
data: @data,
|
119
|
+
callback: {
|
120
|
+
url: @callback
|
121
|
+
}
|
48
122
|
}
|
49
123
|
end
|
124
|
+
|
125
|
+
# Resets instance variables after request is sent
|
126
|
+
def empty_variables
|
127
|
+
@payload = {}
|
128
|
+
@inputs = {}
|
129
|
+
@methods = []
|
130
|
+
@refs = {}
|
131
|
+
@type = 'jpeg'
|
132
|
+
@url = ''
|
133
|
+
@data = {}
|
134
|
+
@callback = ''
|
135
|
+
end
|
50
136
|
end
|