tumble 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Tumble #
2
+
data/Rakefile ADDED
@@ -0,0 +1,80 @@
1
+ require 'date'
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :test
5
+
6
+ ## helper functions
7
+
8
+ def name
9
+ @name ||= Dir['*.gemspec'].first.split('.').first
10
+ end
11
+
12
+ def version
13
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
14
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
15
+ end
16
+
17
+ def gemspec_file
18
+ "#{name}.gemspec"
19
+ end
20
+
21
+ def gem_file
22
+ "#{name}-#{version}.gem"
23
+ end
24
+
25
+ def replace_header(head, header_name)
26
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
27
+ end
28
+
29
+ ## standard tasks
30
+
31
+ RSpec::Core::RakeTask.new(:test)
32
+
33
+ desc "Open an irb session preloaded with this library"
34
+ task :console do
35
+ sh "irb -rubygems -r ./lib/#{name}.rb"
36
+ end
37
+
38
+ ## release management tasks
39
+
40
+ desc "Commit, create tag v#{version} and build and push #{gem_file} to Rubygems"
41
+ task :release => :build do
42
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
43
+ sh "git tag v#{version}"
44
+ sh "git push"
45
+ sh "git push origin v#{version}"
46
+ sh "gem push pkg/#{gem_file}"
47
+ end
48
+
49
+ desc "Build #{gem_file} into the pkg directory"
50
+ task :build => :gemspec do
51
+ sh "mkdir -p pkg"
52
+ sh "gem build #{gemspec_file}"
53
+ sh "mv #{gem_file} pkg"
54
+ end
55
+
56
+ desc "Generate #{gemspec_file}"
57
+ task :gemspec do
58
+ # read spec file and split out manifest section
59
+ spec = File.read(gemspec_file)
60
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
61
+
62
+ # replace name version and date
63
+ replace_header(head, :name)
64
+ replace_header(head, :version)
65
+
66
+ # determine file list from git ls-files
67
+ files = `git ls-files`.
68
+ split("\n").
69
+ sort.
70
+ reject { |file| file =~ /^\./ }.
71
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
72
+ map { |file| " #{file}" }.
73
+ join("\n")
74
+
75
+ # piece file back together and write
76
+ manifest = " s.files = %w[\n#{files}\n ]\n"
77
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
78
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
79
+ puts "Updated #{gemspec_file}"
80
+ end
@@ -0,0 +1,14 @@
1
+ module Tumble
2
+ class Blog
3
+ def initialize(client, name)
4
+ @client = client
5
+ @name = name
6
+ end
7
+
8
+ attr_reader :name
9
+
10
+ def info
11
+ @client.connection.get("blog/#{name}/info")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,54 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ module Tumble
5
+ class Client
6
+
7
+ # Initialize a client to use for making requests
8
+ #
9
+ # @param [String] oauth_token
10
+ # @param [Hash] options
11
+ # @option options Hash :ssl Additional SSL options (like the path to certificate file)
12
+ def initialize(oauth_token, options={})
13
+ @oauth_token = options[:oauth_token]
14
+ @ssl = options[:ssl].nil? ? Hash.new : options[:ssl]
15
+ end
16
+
17
+ def ssl
18
+ @ssl
19
+ end
20
+
21
+ def connection
22
+ options = {
23
+ :url => api_url,
24
+ :ssl => @ssl,
25
+ :params => { :oauth_token => @oauth_token },
26
+ :headers => default_headers
27
+ }
28
+ @connection ||= Faraday::Connection.new(options) do |builder|
29
+ builder.use Faraday::Request::Multipart
30
+ builder.use Faraday::Request::UrlEncoded
31
+ builder.use FaradayMiddleware::Mashify
32
+ builder.use FaradayMiddleware::ParseJson
33
+ builder.adapter Faraday.default_adapter
34
+ end
35
+ end
36
+
37
+ def api_url
38
+ 'http://api.tumblr.com/v2'
39
+ end
40
+
41
+ def blog(blog_name)
42
+ Blog.new(self, blog_name)
43
+ end
44
+
45
+ private
46
+
47
+ def default_headers
48
+ headers = {
49
+ :accept => 'application/json',
50
+ :user_agent => 'tumble'
51
+ }
52
+ end
53
+ end
54
+ end
data/lib/tumble.rb ADDED
@@ -0,0 +1,7 @@
1
+ %w(blog client).each do |file|
2
+ require File.join(File.dirname(__FILE__), 'tumble', file)
3
+ end
4
+
5
+ module Tumble
6
+ VERSION = '0.0.2'
7
+ end
data/spec/blog_spec.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tumble::Blog do
4
+ let(:client) { Tumble::Client.new('token') }
5
+ let(:blog) { client.blog('testy') }
6
+
7
+ it 'should give me its name' do
8
+ blog.name.should == 'testy'
9
+ end
10
+
11
+ it 'should give me info about the blog' do
12
+ blog.info.should == 'ack'
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tumble::Client do
4
+ it 'should return a connection' do
5
+ Tumble::Client.new('token').connection.should be_an_instance_of(Faraday::Connection)
6
+ end
7
+
8
+ it 'should return a blog' do
9
+ blog = Tumble::Client.new('token').blog('testy')
10
+ blog.should be_an_instance_of(Tumble::Blog)
11
+ blog.name.should == 'testy'
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ require 'tumble'
2
+
3
+ require 'webmock/rspec'
4
+
5
+ # WebMock.disable_net_connect!
6
+ WebMock.allow_net_connect!
data/tumble.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
4
+
5
+ s.name = 'tumble'
6
+ s.version = '0.0.2'
7
+
8
+ s.summary = 'Library for accessing the Tumblr api v2'
9
+ # TODO: s.description
10
+
11
+ s.authors = ['Aubrey Holland']
12
+ s.email = 'aubreyholland@gmail.com'
13
+ s.homepage = 'https://github.com/aub/tumble'
14
+
15
+ s.add_dependency 'faraday'
16
+ s.add_development_dependency 'rake'
17
+ s.add_development_dependency 'rspec'
18
+ s.add_development_dependency 'webmock'
19
+
20
+ # = MANIFEST =
21
+ s.files = %w[
22
+ Gemfile
23
+ README.md
24
+ Rakefile
25
+ lib/tumble.rb
26
+ lib/tumble/blog.rb
27
+ lib/tumble/client.rb
28
+ spec/blog_spec.rb
29
+ spec/client_spec.rb
30
+ spec/spec_helper.rb
31
+ tumble.gemspec
32
+ ]
33
+ # = MANIFEST =
34
+
35
+ s.test_files = s.files.select { |path| path =~ %r{^test/*/.+\.rb} }
36
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tumble
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aubrey Holland
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-17 00:00:00.000000000 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: faraday
17
+ requirement: &70198851703960 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70198851703960
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: &70198851703500 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *70198851703500
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &70198851703080 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70198851703080
48
+ - !ruby/object:Gem::Dependency
49
+ name: webmock
50
+ requirement: &70198851702660 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *70198851702660
59
+ description:
60
+ email: aubreyholland@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - lib/tumble.rb
69
+ - lib/tumble/blog.rb
70
+ - lib/tumble/client.rb
71
+ - spec/blog_spec.rb
72
+ - spec/client_spec.rb
73
+ - spec/spec_helper.rb
74
+ - tumble.gemspec
75
+ has_rdoc: true
76
+ homepage: https://github.com/aub/tumble
77
+ licenses: []
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.3.5
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 1.6.2
97
+ signing_key:
98
+ specification_version: 2
99
+ summary: Library for accessing the Tumblr api v2
100
+ test_files: []