ubersmith 1.0.1 → 1.0.2
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.
- data/lib/ubersmith/client.rb +22 -15
- data/lib/ubersmith/url_maker.rb +1 -1
- metadata +3 -3
data/lib/ubersmith/client.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
require 'net/https'
|
|
2
2
|
require 'uri'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'fileutils'
|
|
3
5
|
require 'ubersmith/url_maker'
|
|
4
6
|
|
|
5
7
|
"""
|
|
@@ -23,7 +25,6 @@ module Ubersmith
|
|
|
23
25
|
def initialize(options)
|
|
24
26
|
@config_file_path = options[:config_file_path]
|
|
25
27
|
@debug = options[:debug]
|
|
26
|
-
puts "debug: #{@debug}"
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
def method_missing(method, *args)
|
|
@@ -34,27 +35,21 @@ module Ubersmith
|
|
|
34
35
|
options ||= {}
|
|
35
36
|
cache = options.delete(:cache)
|
|
36
37
|
cache = true if cache.nil?
|
|
37
|
-
ret =
|
|
38
|
+
ret = call_api(build_url(BASE_URL, {
|
|
38
39
|
:method => components[0] + '.' + components[1],
|
|
39
40
|
}.merge(options)), :cache => cache)
|
|
40
|
-
JSON.parse(ret)
|
|
41
|
+
ret = JSON.parse(ret)
|
|
42
|
+
raise ret['error_message'] if ret['status'] == false
|
|
43
|
+
ret['data']
|
|
41
44
|
end
|
|
42
45
|
|
|
43
46
|
private
|
|
44
|
-
def
|
|
47
|
+
def call_api(url, options = {})
|
|
45
48
|
options[:filename] ||= tmp_dir + "/" + safe_filename(url) if options[:cache]
|
|
46
49
|
if options[:filename] && File.exists?(options[:filename])
|
|
47
50
|
ret = File.read(options[:filename])
|
|
48
51
|
else
|
|
49
|
-
|
|
50
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
|
51
|
-
http.use_ssl = (uri.scheme == 'https')
|
|
52
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
53
|
-
puts "HTTP GET #{uri.request_uri}" if @debug
|
|
54
|
-
req = Net::HTTP::Get.new(uri.request_uri)
|
|
55
|
-
req.basic_auth auth_params['api_login'], auth_params['api_pass']
|
|
56
|
-
res = http.start { |http| http.request(req) }
|
|
57
|
-
ret = res.body
|
|
52
|
+
ret = get(url)
|
|
58
53
|
if options[:filename]
|
|
59
54
|
FileUtils.makedirs(File.dirname(options[:filename]))
|
|
60
55
|
File.open(options[:filename], "wb") { |f| f.write(ret) }
|
|
@@ -62,11 +57,23 @@ module Ubersmith
|
|
|
62
57
|
end
|
|
63
58
|
ret
|
|
64
59
|
end
|
|
65
|
-
|
|
60
|
+
|
|
61
|
+
def get(url)
|
|
62
|
+
uri = URI.parse(url)
|
|
63
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
64
|
+
http.use_ssl = (uri.scheme == 'https')
|
|
65
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
66
|
+
puts "HTTP GET #{uri.request_uri}" if @debug
|
|
67
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
|
68
|
+
req.basic_auth auth_params['api_login'], auth_params['api_pass']
|
|
69
|
+
res = http.start { |http| http.request(req) }
|
|
70
|
+
res.body
|
|
71
|
+
end
|
|
72
|
+
|
|
66
73
|
def config
|
|
67
74
|
return @config unless @config.nil?
|
|
68
75
|
@config = File.open(@config_file_path) { |f| YAML::load(f) } rescue nil
|
|
69
|
-
if @config.
|
|
76
|
+
if @config.nil?
|
|
70
77
|
puts "Could not load ubersmith config from #{@config_file_path}"
|
|
71
78
|
return {}
|
|
72
79
|
end
|
data/lib/ubersmith/url_maker.rb
CHANGED
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 1
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
version: 1.0.
|
|
8
|
+
- 2
|
|
9
|
+
version: 1.0.2
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- David Wegman
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2011-12-
|
|
17
|
+
date: 2011-12-05 00:00:00 -08:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies: []
|
|
20
20
|
|