Skip to content

Commit

Permalink
.tumblr generation flow
Browse files Browse the repository at this point in the history
  • Loading branch information
seejohnrun committed Jan 20, 2013
1 parent 1da408e commit d6aa59f
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 7 deletions.
43 changes: 43 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,43 @@
PATH
remote: .
specs:
tumblr_client (0.6.8)
faraday (>= 0.8)
faraday_middleware
json
oauth

GEM
remote: http://rubygems.org/
specs:
addressable (2.3.2)
crack (0.3.2)
diff-lcs (1.1.3)
faraday (0.8.4)
multipart-post (~> 1.1)
faraday_middleware (0.9.0)
faraday (>= 0.7.4, < 0.9)
json (1.7.6)
multipart-post (1.1.5)
oauth (0.4.7)
rake (10.0.3)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.1)
webmock (1.9.0)
addressable (>= 2.2.7)
crack (>= 0.1.7)

PLATFORMS
ruby

DEPENDENCIES
rake
rspec
tumblr_client!
webmock
58 changes: 51 additions & 7 deletions bin/tumblr
Expand Up @@ -2,21 +2,65 @@
$:.unshift File.join File.dirname(__FILE__), '..', 'lib'
require 'rubygems'
require 'tumblr_client'
require 'oauth'
require 'yaml'
require 'irb'
require 'irb/completion'

configuration = YAML.load_file File.join ENV['HOME'], '.tumblr' rescue {}
path = File.join ENV['HOME'], '.tumblr'

ENV['IRBRC'] = '.irbrc' if File.exists? '.irbrc'
if File.exist?(path)

# Load configuration from data
configuration = YAML.load_file path
Tumblr.configure do |config|
Tumblr::Config::VALID_OPTIONS_KEYS.each do |key|
config.send(:"#{key}=", configuration[key.to_s])
end
end

else

Tumblr.configure do |config|

puts "Register an application at: http://www.tumblr.com/oauth/apps"
print 'OAuth Consumer key: '
config.consumer_key = gets.chomp

print 'OAuth Consumer secret: '
config.consumer_secret = gets.chomp

site = 'http://www.tumblr.com'
consumer = OAuth::Consumer.new(config.consumer_key, config.consumer_secret, :site => site)
request_token = consumer.get_request_token

puts

puts request_token.authorize_url
puts "Post-redirect, copy the oauth_verifier"
print 'OAuth Verifier: '
verifier = gets.chomp

access_token = request_token.get_access_token :oauth_verifier => verifier
config.oauth_token = access_token.token
config.oauth_token_secret = access_token.secret

end

# Save credentials
File.open(path, 'w') do |f|
configuration = {}
Tumblr::Config::VALID_OPTIONS_KEYS.each do |key|
configuration[key.to_s] = Tumblr.send(key)
end
f.write YAML.dump configuration
end

Tumblr.configure do |config|
config.consumer_key = configuration["consumer_key"]
config.consumer_secret = configuration["consumer_secret"]
config.oauth_token = configuration["oauth_token"]
config.oauth_token_secret = configuration["oauth_token_secret"]
end


ENV['IRBRC'] = '.irbrc' if File.exists? '.irbrc'

puts %q[
. .o8 oooo
.o8 "888 `888
Expand Down
1 change: 1 addition & 0 deletions tumblr.gemspec
Expand Up @@ -4,6 +4,7 @@ Gem::Specification.new do |gem|
gem.add_dependency 'faraday', '>= 0.8'
gem.add_dependency 'faraday_middleware'
gem.add_dependency 'json'
gem.add_dependency 'oauth'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'webmock'
Expand Down

0 comments on commit d6aa59f

Please sign in to comment.