geppetto 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/geppetto/cli.rb +1 -1
- data/lib/geppetto/version.rb +1 -1
- data/lib/geppetto.rb +93 -1
- metadata +4 -4
data/lib/geppetto/cli.rb
CHANGED
@@ -151,7 +151,7 @@ module Geppetto
|
|
151
151
|
def generate_images
|
152
152
|
users_hash = get_test_users
|
153
153
|
say "Posting images for #{users_hash.size} users", :white
|
154
|
-
progress = ProgressBar.new("Images", users_hash.size)
|
154
|
+
progress = ProgressBar.new("Images", users_hash.size*2)
|
155
155
|
users_hash.each{|user_hash|
|
156
156
|
# Get this user's feed
|
157
157
|
@graph = Facebook::GraphAPI.new(get_token_for_user_id(user_hash['id']))
|
data/lib/geppetto/version.rb
CHANGED
data/lib/geppetto.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'geppetto/version'
|
2
|
+
require 'geppetto/logging'
|
2
3
|
require 'net/http'
|
4
|
+
require 'koala'
|
5
|
+
require 'logger'
|
3
6
|
|
4
|
-
#
|
7
|
+
# Monkey patch to suppress 'warning: peer certificate won't be verified in this SSL session'
|
5
8
|
class Net::HTTP
|
6
9
|
alias_method :old_initialize, :initialize
|
7
10
|
def initialize(*args)
|
@@ -10,3 +13,92 @@ class Net::HTTP
|
|
10
13
|
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
11
14
|
end
|
12
15
|
end
|
16
|
+
|
17
|
+
|
18
|
+
module Geppetto
|
19
|
+
def self.log(msg)
|
20
|
+
@@log ||= Logger.new("geppetto.log", 'daily')
|
21
|
+
# Filterout client secret
|
22
|
+
match = msg.match(/.*client_secret=([a-z0-9]+)/)
|
23
|
+
msg.sub!(match[1], '[filtered]') if match
|
24
|
+
@@log.debug(msg)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Define our own http service using Net::HTTP so we can log requests for debugging purpose
|
28
|
+
module NetHTTPService
|
29
|
+
# this service uses Net::HTTP to send requests to the graph
|
30
|
+
def self.included(base)
|
31
|
+
base.class_eval do
|
32
|
+
require "net/http" unless defined?(Net::HTTP)
|
33
|
+
require "net/https"
|
34
|
+
require "net/http/post/multipart"
|
35
|
+
|
36
|
+
include Koala::HTTPService
|
37
|
+
|
38
|
+
def self.make_request(path, args, verb, options = {})
|
39
|
+
# We translate args to a valid query string. If post is specified,
|
40
|
+
# we send a POST request to the given path with the given arguments.
|
41
|
+
|
42
|
+
# by default, we use SSL only for private requests
|
43
|
+
# this makes public requests faster
|
44
|
+
private_request = args["access_token"] || @always_use_ssl || options[:use_ssl]
|
45
|
+
|
46
|
+
# if the verb isn't get or post, send it as a post argument
|
47
|
+
args.merge!({:method => verb}) && verb = "post" if verb != "get" && verb != "post"
|
48
|
+
|
49
|
+
http = create_http(server(options), private_request, options)
|
50
|
+
http.use_ssl = true if private_request
|
51
|
+
|
52
|
+
result = http.start do |http|
|
53
|
+
Geppetto.log("#{verb.upcase} #{path} #{encode_params(args)}")
|
54
|
+
response, body = if verb == "post"
|
55
|
+
if params_require_multipart? args
|
56
|
+
http.request Net::HTTP::Post::Multipart.new path, encode_multipart_params(args)
|
57
|
+
else
|
58
|
+
http.post(path, encode_params(args))
|
59
|
+
end
|
60
|
+
else
|
61
|
+
http.get("#{path}?#{encode_params(args)}")
|
62
|
+
end
|
63
|
+
Geppetto.log("#{response.code.to_i} #{body}")
|
64
|
+
Koala::Response.new(response.code.to_i, body, response)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
def self.encode_params(param_hash)
|
70
|
+
# unfortunately, we can't use to_query because that's Rails, not Ruby
|
71
|
+
# if no hash (e.g. no auth token) return empty string
|
72
|
+
((param_hash || {}).collect do |key_and_value|
|
73
|
+
key_and_value[1] = key_and_value[1].to_json if key_and_value[1].class != String
|
74
|
+
"#{key_and_value[0].to_s}=#{CGI.escape key_and_value[1]}"
|
75
|
+
end).join("&")
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.encode_multipart_params(param_hash)
|
79
|
+
Hash[*param_hash.collect do |key, value|
|
80
|
+
[key, value.kind_of?(Koala::UploadableIO) ? value.to_upload_io : value]
|
81
|
+
end.flatten]
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.create_http(server, private_request, options)
|
85
|
+
if options[:proxy]
|
86
|
+
proxy = URI.parse(options[:proxy])
|
87
|
+
http = Net::HTTP.new(server, private_request ? 443 : nil,
|
88
|
+
proxy.host, proxy.port, proxy.user, proxy.password)
|
89
|
+
else
|
90
|
+
http = Net::HTTP.new(server, private_request ? 443 : nil)
|
91
|
+
end
|
92
|
+
if options[:timeout]
|
93
|
+
http.open_timeout = options[:timeout]
|
94
|
+
http.read_timeout = options[:timeout]
|
95
|
+
end
|
96
|
+
http
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
Koala.http_service = Geppetto::NetHTTPService
|
104
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geppetto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 6
|
10
|
+
version: 0.9.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Georges Auberger
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-24 00:00:00 -07:00
|
19
19
|
default_executable: geppetto
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|