hair-api-client 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/hair/api/client.rb +30 -4
- data/lib/hair/api/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34e9613879e52842f022bd1e3e450054e53273b5
|
4
|
+
data.tar.gz: a48f8886576ca9951c83167996c996f8d7541ecd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccdb7efd6435f7b1cd8b13a616d7b4c7c42f36e0ad3611eabc77653c7df5a10af2998a6f016189b4ccd273f601ca77baf555d8c9cf72cd9218198e5f1f07eb70
|
7
|
+
data.tar.gz: 5ac80636c1a508f85ba0533ad45bc544b2086feb5721c01d935ebfb4f3c2a2ec3247abe214fdf5509e6ee71b824d74b77b20de54fc40aa43f62128aa4a8c364a
|
data/README.md
CHANGED
data/lib/hair/api/client.rb
CHANGED
@@ -12,7 +12,9 @@ module Hair
|
|
12
12
|
|
13
13
|
API_ENDPOINT = 'https://api.hair.cm'
|
14
14
|
|
15
|
-
@@options = {
|
15
|
+
@@options = {
|
16
|
+
method: 'get'
|
17
|
+
}
|
16
18
|
|
17
19
|
# Default search options
|
18
20
|
def self.options
|
@@ -29,16 +31,28 @@ module Hair
|
|
29
31
|
yield @@options
|
30
32
|
end
|
31
33
|
|
34
|
+
# Search image by query
|
32
35
|
def self.image_search(query, opts = {})
|
33
36
|
opts[:path] = '/image/search'
|
34
37
|
opts[:query] = query
|
35
38
|
self.send_request(opts)
|
36
39
|
end
|
37
40
|
|
41
|
+
# Record status of use
|
42
|
+
# key is 10 characters, published_at is Time object.
|
43
|
+
def self.record(key, title, url, published_at, opts = {})
|
44
|
+
opts[:method] = 'post'
|
45
|
+
opts[:path] = '/record'
|
46
|
+
opts[:image_key] = key
|
47
|
+
opts[:entry_title] = title
|
48
|
+
opts[:entry_url] = url
|
49
|
+
opts[:approve_date] = published_at.strftime('%Y-%m-%d')
|
50
|
+
self.send_request(opts)
|
51
|
+
end
|
52
|
+
|
38
53
|
def self.send_request(opts)
|
39
54
|
opts = self.options.merge(opts) if self.options
|
40
|
-
|
41
|
-
http_response = Net::HTTP.get_response(URI::parse(request_url))
|
55
|
+
http_response = call_api(opts)
|
42
56
|
res = Response.new(http_response.body)
|
43
57
|
unless http_response.kind_of? Net::HTTPSuccess
|
44
58
|
err_msg = "HTTP Response: #{http_response.code} #{http_response.message}"
|
@@ -74,9 +88,21 @@ module Hair
|
|
74
88
|
|
75
89
|
private
|
76
90
|
|
91
|
+
def self.call_api(opts)
|
92
|
+
http_method = opts.delete(:method)
|
93
|
+
if http_method == 'post'
|
94
|
+
request_url = prepare_url({path: opts.delete(:path)})
|
95
|
+
Net::HTTP.post_form(URI::parse(request_url), opts)
|
96
|
+
else
|
97
|
+
request_url = prepare_url(opts)
|
98
|
+
Net::HTTP.get_response(URI::parse(request_url))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
77
102
|
def self.prepare_url(opts)
|
78
103
|
path = opts.delete(:path)
|
79
|
-
|
104
|
+
query_string = opts.empty? ? '' : '?' + URI.encode_www_form(opts)
|
105
|
+
API_ENDPOINT + path + query_string
|
80
106
|
end
|
81
107
|
|
82
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hair-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takayuki Hasegawa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|