robohash_client 0.1.0 → 0.1.1
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/robohash_client.rb +12 -4
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73484e6dc66a30f7d6b3a7c0fe484083a4b9eacd
|
4
|
+
data.tar.gz: 6234d20731e8edf5c0c9dd7b58a3c5d7ea6bde98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72fd71fd448a059a79ae8d9e1a7facfac9451e44d09d58dcdaaf4560e6dd82add4bcfea465f0112c973456af2083cb11df35a08de1a7d716ac5685b38b4cd92c
|
7
|
+
data.tar.gz: 84e2d68a1463279f0c7d55f94da1bfb666f977849ac51c8b638fc31a6ac38514e68ba90ff5c9acd62caae36770297574a46049a194c8ae903f738e2000ee544f
|
data/lib/robohash_client.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'net/http'
|
2
|
-
require '
|
2
|
+
require 'pry'
|
3
3
|
|
4
4
|
class RobohashClient
|
5
5
|
BASE_URL = 'https://robohash.org'
|
@@ -20,6 +20,9 @@ class RobohashClient
|
|
20
20
|
}
|
21
21
|
|
22
22
|
class << self
|
23
|
+
attr_accessor :default_dir
|
24
|
+
@default_dir = DEFAULT_DIRECTORY
|
25
|
+
|
23
26
|
def get(name, options = {})
|
24
27
|
return 'Name should be an non-empty String!' if invalid_name(name)
|
25
28
|
make_request(name, build_query_string(options))
|
@@ -44,6 +47,10 @@ class RobohashClient
|
|
44
47
|
urls
|
45
48
|
end
|
46
49
|
|
50
|
+
def reset_default_dir
|
51
|
+
@default_dir = DEFAULT_DIRECTORY
|
52
|
+
end
|
53
|
+
|
47
54
|
private
|
48
55
|
|
49
56
|
def extract_valid_names(names)
|
@@ -89,13 +96,14 @@ class RobohashClient
|
|
89
96
|
end
|
90
97
|
|
91
98
|
def save(image, name)
|
92
|
-
|
99
|
+
dir = @default_dir || DEFAULT_DIRECTORY
|
100
|
+
Dir.mkdir(dir) unless Dir.exists? dir
|
93
101
|
|
94
|
-
open("
|
102
|
+
open(File.join("#{dir}", "#{name}.png"), 'wb') do |file|
|
95
103
|
file.write(image.body)
|
96
104
|
end
|
97
105
|
|
98
|
-
puts "Image #{name}.png saved successfully!"
|
106
|
+
puts "Image #{name}.png saved successfully on #{dir}!"
|
99
107
|
rescue => e
|
100
108
|
puts "Error saving image #{name}.png: #{e.message}"
|
101
109
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robohash_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danilo Barion Nogueira
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: A simple client to get robohash avatar's from Robohash.org.
|
28
42
|
email: danilo.barion1986@live.com
|
29
43
|
executables:
|