tumblr-api-v2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ pkg/*
4
+ /nbproject/private/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tumblr-api-v2.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tumblr-api-v2 (0.0.1)
5
+ httparty (~> 0.8.1)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.3)
11
+ fakeweb (1.3.0)
12
+ httparty (0.8.1)
13
+ multi_json
14
+ multi_xml
15
+ multi_json (1.0.3)
16
+ multi_xml (0.4.1)
17
+ rspec (2.7.0)
18
+ rspec-core (~> 2.7.0)
19
+ rspec-expectations (~> 2.7.0)
20
+ rspec-mocks (~> 2.7.0)
21
+ rspec-core (2.7.1)
22
+ rspec-expectations (2.7.0)
23
+ diff-lcs (~> 1.1.2)
24
+ rspec-mocks (2.7.0)
25
+ vcr (2.0.0.beta2)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ fakeweb (~> 1.3.0)
32
+ rspec (~> 2.7)
33
+ tumblr-api-v2!
34
+ vcr (~> 2.0.0.beta2)
@@ -0,0 +1,3 @@
1
+ = Tests
2
+
3
+ To re-record or to create new vcr cassetes you should create the file spec/apikeys.yml there is already a sample on spec/apikeys.yml.sample
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ # If you want to make this the default task
8
+ task :default => :spec
@@ -0,0 +1,24 @@
1
+ module TumblrApiV2
2
+ module ApikeyApi
3
+ def info(blog_url)
4
+ get_on_path(blog_url, '/info')
5
+ end
6
+
7
+ def posts(blog_url)
8
+ get_on_path(blog_url, '/posts')
9
+ end
10
+
11
+ private
12
+
13
+ def get_on_path(blog_url, path)
14
+ raise TumblrError unless has_apikey_access?
15
+
16
+ blog_domain = filter_blog_domain(blog_url)
17
+ get_blog_api("/#{blog_domain}#{path}", query: apikey_option)
18
+ end
19
+
20
+ def filter_blog_domain(blog_url)
21
+ blog_url.gsub(/^https?:\/\//, '').chomp('/')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ require "tumblr-api-v2/apikey_api"
2
+ require "httparty"
3
+
4
+ module TumblrApiV2
5
+ class TumblrError < StandardError; end
6
+
7
+ class Client
8
+ include ApikeyApi
9
+
10
+ include HTTParty
11
+ base_uri 'http://api.tumblr.com/v2'
12
+
13
+ attr_reader :consumer_key
14
+
15
+ def initialize(consumer_key = nil)
16
+ @consumer_key = consumer_key
17
+ end
18
+
19
+ private
20
+
21
+ def get_blog_api(path, options = {})
22
+ self.class.get("/blog#{path}", options)
23
+ end
24
+
25
+ def apikey_option
26
+ { api_key: @consumer_key }
27
+ end
28
+
29
+ def has_apikey_access?
30
+ not @consumer_key.nil?
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module TumblrApiV2
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ require "tumblr-api-v2/version"
2
+ require "tumblr-api-v2/client"
3
+
data/spec/.gitignore ADDED
@@ -0,0 +1 @@
1
+ apikeys.yml
@@ -0,0 +1 @@
1
+ consumer-key: <you-consumer-key>
@@ -0,0 +1,75 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.tumblr.com:80/v2/blog/fgiusti-test-data.tumblr.com/info?api_key=<CONSUMER-KEY>
6
+ body: ''
7
+ headers:
8
+ connection:
9
+ - close
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ p3p:
16
+ - CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
17
+ vary:
18
+ - Accept-Encoding
19
+ x-tumblr-usec:
20
+ - D=43677
21
+ content-type:
22
+ - application/json
23
+ content-length:
24
+ - '250'
25
+ date:
26
+ - Wed, 07 Dec 2011 23:46:48 GMT
27
+ connection:
28
+ - close
29
+ body: ! '{"meta":{"status":200,"msg":"OK"},"response":{"blog":{"title":"Cool blog.","posts":6,"name":"fgiusti-test-data","url":"http:\/\/fgiusti-test-data.tumblr.com\/","updated":1323094225,"description":"That''s
30
+ the blog description.","ask":false,"likes":0}}}'
31
+ http_version: '1.1'
32
+ recorded_at: Wed, 07 Dec 2011 23:46:48 GMT
33
+ - request:
34
+ method: get
35
+ uri: http://api.tumblr.com:80/v2/blog/fgiusti-test-data.tumblr.com/posts?api_key=<CONSUMER-KEY>
36
+ body: ''
37
+ headers:
38
+ connection:
39
+ - close
40
+ response:
41
+ status:
42
+ code: 200
43
+ message: OK
44
+ headers:
45
+ p3p:
46
+ - CP="ALL ADM DEV PSAi COM OUR OTRo STP IND ONL"
47
+ vary:
48
+ - Accept-Encoding
49
+ x-tumblr-usec:
50
+ - D=69486
51
+ content-type:
52
+ - application/json
53
+ content-length:
54
+ - '6956'
55
+ date:
56
+ - Wed, 07 Dec 2011 23:46:49 GMT
57
+ connection:
58
+ - close
59
+ body: ! '{"meta":{"status":200,"msg":"OK"},"response":{"blog":{"title":"Cool blog.","posts":6,"name":"fgiusti-test-data","url":"http:\/\/fgiusti-test-data.tumblr.com\/","updated":1323094225,"description":"That''s
60
+ the blog description.","ask":false,"likes":0},"posts":[{"blog_name":"fgiusti-test-data","id":13778790958,"post_url":"http:\/\/fgiusti-test-data.tumblr.com\/post\/13778790958\/fabiogiolito-via-mentally-moonwalk-on-we-heart","type":"photo","date":"2011-12-05
61
+ 14:10:25 GMT","timestamp":1323094225,"format":"html","reblog_key":"NLLHgG8u","tags":[],"bookmarklet":true,"note_count":1,"source_url":"http:\/\/weheartit.com\/entry\/16697103","source_title":"weheartit.com","caption":"<p><a
62
+ class=\"tumblr_blog\" href=\"http:\/\/fabiogiolito.tumblr.com\/post\/11953490550\/via-mentally-moonwalk-on-we-heart-it-visual\">fabiogiolito<\/a>:<\/p>\n<blockquote>\n<p>(via
63
+ <a href=\"http:\/\/weheartit.com\/entry\/16697103\">mentally moonwalk on we
64
+ heart it \/ visual bookmark #16697103<\/a>)<\/p>\n<\/blockquote>","link_url":"http:\/\/weheartit.com\/entry\/16697103","photos":[{"caption":"","alt_sizes":[{"width":500,"height":333,"url":"http:\/\/24.media.tumblr.com\/tumblr_lton8rxDeC1qz6o2so1_500.jpg"},{"width":400,"height":266,"url":"http:\/\/24.media.tumblr.com\/tumblr_lton8rxDeC1qz6o2so1_400.jpg"},{"width":250,"height":167,"url":"http:\/\/27.media.tumblr.com\/tumblr_lton8rxDeC1qz6o2so1_250.jpg"},{"width":100,"height":67,"url":"http:\/\/29.media.tumblr.com\/tumblr_lton8rxDeC1qz6o2so1_100.jpg"},{"width":75,"height":75,"url":"http:\/\/27.media.tumblr.com\/tumblr_lton8rxDeC1qz6o2so1_75sq.jpg"}],"original_size":{"width":500,"height":333,"url":"http:\/\/24.media.tumblr.com\/tumblr_lton8rxDeC1qz6o2so1_500.jpg"}}]},{"blog_name":"fgiusti-test-data","id":13778716798,"post_url":"http:\/\/fgiusti-test-data.tumblr.com\/post\/13778716798","type":"photo","date":"2011-12-05
65
+ 14:06:00 GMT","timestamp":1323093960,"format":"html","reblog_key":"WW1t7eg6","tags":[],"bookmarklet":true,"note_count":0,"caption":"","link_url":"http:\/\/www.tumblr.com\/goodies","photos":[{"caption":"","alt_sizes":[{"width":500,"height":285,"url":"http:\/\/27.media.tumblr.com\/tumblr_lvqhvjaDfp1ql0y4eo1_500.png"},{"width":400,"height":228,"url":"http:\/\/27.media.tumblr.com\/tumblr_lvqhvjaDfp1ql0y4eo1_400.png"},{"width":250,"height":142,"url":"http:\/\/29.media.tumblr.com\/tumblr_lvqhvjaDfp1ql0y4eo1_250.png"},{"width":100,"height":57,"url":"http:\/\/25.media.tumblr.com\/tumblr_lvqhvjaDfp1ql0y4eo1_100.png"},{"width":75,"height":75,"url":"http:\/\/27.media.tumblr.com\/tumblr_lvqhvjaDfp1ql0y4eo1_75sq.png"}],"original_size":{"width":803,"height":457,"url":"http:\/\/www.tumblr.com\/photo\/1280\/13778716798\/1\/tumblr_lvqhvjaDfp1ql0y4e"}}]},{"blog_name":"fgiusti-test-data","id":13777915012,"post_url":"http:\/\/fgiusti-test-data.tumblr.com\/post\/13777915012","type":"photo","date":"2011-12-05
66
+ 13:27:00 GMT","timestamp":1323091620,"format":"html","reblog_key":"pu8UiaYK","tags":[],"note_count":1,"source_url":"http:\/\/google.com","source_title":"google.com","caption":"","link_url":"http:\/\/instagr.am\/p\/XdCQP\/","photos":[{"caption":"","alt_sizes":[{"width":500,"height":500,"url":"http:\/\/26.media.tumblr.com\/tumblr_lvpth4JpTp1r18psxo1_500.jpg"},{"width":400,"height":400,"url":"http:\/\/30.media.tumblr.com\/tumblr_lvpth4JpTp1r18psxo1_400.jpg"},{"width":250,"height":250,"url":"http:\/\/24.media.tumblr.com\/tumblr_lvpth4JpTp1r18psxo1_250.jpg"},{"width":100,"height":100,"url":"http:\/\/28.media.tumblr.com\/tumblr_lvpth4JpTp1r18psxo1_100.jpg"},{"width":75,"height":75,"url":"http:\/\/30.media.tumblr.com\/tumblr_lvpth4JpTp1r18psxo1_75sq.jpg"}],"original_size":{"width":612,"height":612,"url":"http:\/\/www.tumblr.com\/photo\/1280\/13777915012\/1\/tumblr_lvpth4JpTp1r18psx"}}]},{"blog_name":"fgiusti-test-data","id":13777433529,"post_url":"http:\/\/fgiusti-test-data.tumblr.com\/post\/13777433529\/three-photos-testing","type":"photo","date":"2011-12-05
67
+ 13:03:22 GMT","timestamp":1323090202,"format":"html","reblog_key":"4rWKbjM7","tags":[],"note_count":0,"caption":"<p>three
68
+ photos testing<\/p>","photos":[{"caption":"","alt_sizes":[{"width":75,"height":75,"url":"http:\/\/28.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo1_75sq.gif"}],"original_size":{"width":37,"height":30,"url":"http:\/\/25.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo1_100.gif"}},{"caption":"","alt_sizes":[{"width":500,"height":602,"url":"http:\/\/27.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo3_500.png"},{"width":400,"height":482,"url":"http:\/\/29.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo3_400.png"},{"width":250,"height":301,"url":"http:\/\/27.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo3_250.png"},{"width":100,"height":120,"url":"http:\/\/28.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo3_100.png"},{"width":75,"height":75,"url":"http:\/\/29.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo3_75sq.png"}],"original_size":{"width":620,"height":747,"url":"http:\/\/27.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo3_500.png"}},{"caption":"","alt_sizes":[{"width":500,"height":500,"url":"http:\/\/25.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo2_500.jpg"},{"width":400,"height":400,"url":"http:\/\/27.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo2_400.jpg"},{"width":250,"height":250,"url":"http:\/\/30.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo2_250.jpg"},{"width":100,"height":100,"url":"http:\/\/25.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo2_100.jpg"},{"width":75,"height":75,"url":"http:\/\/30.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo2_75sq.jpg"}],"original_size":{"width":1000,"height":1000,"url":"http:\/\/25.media.tumblr.com\/tumblr_lvqexmpiJF1ql0y4eo2_500.jpg"}}]},{"blog_name":"fgiusti-test-data","id":6140566000,"post_url":"http:\/\/fgiusti-test-data.tumblr.com\/post\/6140566000\/first-job","type":"text","date":"2011-06-03
69
+ 12:47:53 GMT","timestamp":1307105273,"format":"html","reblog_key":"tqgpzGnt","tags":["portfolio"],"note_count":0,"title":"First
70
+ job","body":"<p>cool<\/p>"},{"blog_name":"fgiusti-test-data","id":6140355204,"post_url":"http:\/\/fgiusti-test-data.tumblr.com\/post\/6140355204\/thats-a-test-post","type":"photo","date":"2011-06-03
71
+ 12:35:00 GMT","timestamp":1307104500,"format":"html","reblog_key":"aTYcCV4H","tags":["normal"],"note_count":0,"caption":"<p>That&#8217;s
72
+ a test post.<\/p>","photos":[{"caption":"","alt_sizes":[{"width":500,"height":500,"url":"http:\/\/29.media.tumblr.com\/tumblr_lm7saugBku1ql0y4eo1_500.jpg"},{"width":400,"height":400,"url":"http:\/\/26.media.tumblr.com\/tumblr_lm7saugBku1ql0y4eo1_400.jpg"},{"width":250,"height":250,"url":"http:\/\/27.media.tumblr.com\/tumblr_lm7saugBku1ql0y4eo1_250.jpg"},{"width":100,"height":100,"url":"http:\/\/28.media.tumblr.com\/tumblr_lm7saugBku1ql0y4eo1_100.jpg"},{"width":75,"height":75,"url":"http:\/\/29.media.tumblr.com\/tumblr_lm7saugBku1ql0y4eo1_75sq.jpg"}],"original_size":{"width":1060,"height":1060,"url":"http:\/\/www.tumblr.com\/photo\/1280\/6140355204\/1\/tumblr_lm7saugBku1ql0y4e"}}]}],"total_posts":6}}'
73
+ http_version: '1.1'
74
+ recorded_at: Wed, 07 Dec 2011 23:46:49 GMT
75
+ recorded_with: VCR 2.0.0.beta2
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'tumblr-api-v2'
5
+
6
+ # VCR configuration
7
+ require 'vcr'
8
+
9
+ apikeys = YAML.load_file("spec/apikeys.yml")
10
+ CONSUMER_KEY = apikeys['consumer-key']
11
+
12
+ VCR.configure do |c|
13
+ c.hook_into :fakeweb
14
+ c.cassette_library_dir = 'spec/cassettes'
15
+ c.default_cassette_options = { :record => :new_episodes }
16
+ # c.default_cassette_options = { :record => :none }
17
+ c.filter_sensitive_data('<CONSUMER-KEY>') { CONSUMER_KEY }
18
+ end
19
+
20
+ RSpec.configure do |c|
21
+ c.extend VCR::RSpec::Macros
22
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe TumblrApiV2::ApikeyApi do
4
+ use_vcr_cassette
5
+
6
+ it "without a consumer key should raise an exception" do
7
+ expect do
8
+ TumblrApiV2::Client.new.info('http://fgiusti-test-data.tumblr.com/')
9
+ end.to raise_error(TumblrApiV2::TumblrError)
10
+ end
11
+
12
+ describe "with a valid consumer key" do
13
+ before(:each) do
14
+ @client = TumblrApiV2::Client.new(CONSUMER_KEY)
15
+ end
16
+
17
+ describe "#info" do
18
+ it "should get blog's info" do
19
+ info = @client.info('http://fgiusti-test-data.tumblr.com/')
20
+ info['response']['blog']['title'].should == 'Cool blog.'
21
+ end
22
+ end
23
+
24
+ describe "#posts" do
25
+ it "should get blog's posts" do
26
+ info = @client.posts('http://fgiusti-test-data.tumblr.com/')
27
+ info['response']['posts'].last['post_url'].should == 'http://fgiusti-test-data.tumblr.com/post/6140355204/thats-a-test-post'
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe TumblrApiV2::Client do
4
+ it "should instance a Client" do
5
+ TumblrApiV2::Client.new.should be_a(TumblrApiV2::Client)
6
+ end
7
+
8
+ it "should instance a Client with a consumer key" do
9
+ c = TumblrApiV2::Client.new('fake-consumer-key')
10
+ c.consumer_key.should == 'fake-consumer-key'
11
+ end
12
+ end
13
+
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "tumblr-api-v2/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "tumblr-api-v2"
7
+ s.version = TumblrApiV2::VERSION
8
+ s.authors = ["Filipe Giusti"]
9
+ s.email = ["filipegiusti@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Wrapper for Tumblr API v2}
12
+ s.description = %q{Wrapper for Tumblr API v2}
13
+ s.homepage = 'https://github.com/filipegiusti/tumblr-api-v2'
14
+
15
+ s.rubyforge_project = "tumblr-api-v2"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'httparty', '~> 0.8.1'
23
+ s.add_development_dependency 'rspec', '~> 2.7'
24
+ s.add_development_dependency 'vcr', '~> 2.0.0.beta2'
25
+ s.add_development_dependency 'fakeweb', '~> 1.3.0' # for vcr
26
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tumblr-api-v2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Filipe Giusti
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &86643720 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *86643720
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &86643440 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.7'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *86643440
36
+ - !ruby/object:Gem::Dependency
37
+ name: vcr
38
+ requirement: &86643200 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.0.0.beta2
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *86643200
47
+ - !ruby/object:Gem::Dependency
48
+ name: fakeweb
49
+ requirement: &86642940 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *86642940
58
+ description: Wrapper for Tumblr API v2
59
+ email:
60
+ - filipegiusti@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - .rspec
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - README_DEVELOPMENT
70
+ - Rakefile
71
+ - lib/tumblr-api-v2.rb
72
+ - lib/tumblr-api-v2/apikey_api.rb
73
+ - lib/tumblr-api-v2/client.rb
74
+ - lib/tumblr-api-v2/version.rb
75
+ - spec/.gitignore
76
+ - spec/apikeys.yml.sample
77
+ - spec/cassettes/TumblrApiV2_ApikeyApi.yml
78
+ - spec/spec_helper.rb
79
+ - spec/tumblr-api-v2/apikey_api_spec.rb
80
+ - spec/tumblr-api-v2/client_spec.rb
81
+ - tumblr-api-v2.gemspec
82
+ homepage: https://github.com/filipegiusti/tumblr-api-v2
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project: tumblr-api-v2
102
+ rubygems_version: 1.8.11
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Wrapper for Tumblr API v2
106
+ test_files: []