tumblr_client_wrapper 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bb64f24fd80ae798bc17443657edb9cc31cb18bf
4
+ data.tar.gz: 2c6b48272178f347c2489c73b5887c7a58450a0e
5
+ SHA512:
6
+ metadata.gz: 8868cb49e4c40c350e80485ff3eaaf02fe3287c328ebd1aa6ef86607223715a955fa7d5c250e34c1640d149fc66432d4cd37beb834ff566a3285a178b00dec6f
7
+ data.tar.gz: 822c3302e3d8e27418da22830cbb37c8e9361f0e770299de4064976f3eeffd855d642789086a472513f676eb1cc6a4a045956dc647ca2e5ad65a8a194b0cd973
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ tumblr_client_wrapper-0.1.0.gem
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ branches:
3
+ only:
4
+ - master
5
+ rvm:
6
+ - 2.2
7
+ env:
8
+ - RAILS_VERSION="~> 4.2.0"
9
+
10
+ before_install:
11
+ - gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tumblr_client_wrapper.gemspec
4
+ gemspec
5
+
6
+ gem 'tumblr_client'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Richardson Dackam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,100 @@
1
+ [![Build Status](https://travis-ci.org/richardsondx/tumblr_client_wrapper.svg?branch=master)](https://travis-ci.org/richardsondx/tumblr_client_wrapper)
2
+
3
+ # The Tumblr Client Wrapper
4
+
5
+ This gem allows you to easily embed tumblr posts ( Text, Photo, Quote, Link, Chat Audio, Video, Answer) to your ruby on rails view.
6
+
7
+ It's a Ruby Wrapper for the Tumblr-client official gem and Tumblr v2 API.
8
+
9
+ View the [DEMO](http://tumblr-client-wrapper.herokuapp.com)
10
+
11
+ ## Installation
12
+
13
+ Add these lines to your application's Gemfile:
14
+
15
+ gem 'tumblr-client-wrapper'
16
+ gem 'tumblr-client'
17
+
18
+
19
+ ## What You Need
20
+
21
+ Get an OAuth key on the Tumblr websie by registering your application
22
+
23
+ ## Configuration
24
+
25
+ Tumblr Client Wrapper uses Tumblr-Client configuration.
26
+
27
+ Tumblr.configure do |config|
28
+ config.consumer_key = "consumer_key"
29
+ config.consumer_secret = "consumer_secret"
30
+ config.oauth_token = "access_token"
31
+ config.oauth_token_secret = "access_token_secret"
32
+ end
33
+
34
+ To get your consumer key [register your application](register an application)
35
+
36
+ Use the [console](https://api.tumblr.com/console) to get your oauth_token and oauth_token_secret
37
+
38
+
39
+ ## Usage
40
+
41
+ example: blogid.tumblr.com
42
+
43
+ In your view: add the following to Add *All Posts* from your blog
44
+
45
+ <%= embed_tumblr("blogid") %>
46
+
47
+ You can also specify an options and request the gem to only display posts that are photos, quotes or text
48
+ by passing an option :type followed by the type of post you'd like to dislay.
49
+
50
+ <%= embed_tumblr("blogid", {type: "quotes"}) %>
51
+
52
+ Tumblr has 8 differents type of posts: Text, Photo, Quote, Link, Chat, Audio, Video, Answer
53
+
54
+ valid *options* you can pass are:
55
+
56
+ `:params, :id, :tag, :limit, :offset, :reblog_info, :type, :notes_info, :filter`
57
+
58
+ You can pass additional options:
59
+
60
+ <%= embed_tumblr("blogid", {type: :quote, limit: 20}) %>
61
+
62
+ ## Add Default or Custom Style
63
+
64
+ To use the default style of the gem add the following line to application.css
65
+
66
+ *= require tumblr_client_wrapper.css
67
+
68
+ You can edit the style of the posts by updating the following CSS classes
69
+
70
+ .post_content{}
71
+ .post_content .post_title{}
72
+ .post_content .post_title blockquote{}
73
+ .post_content .extra_large{}
74
+ .post_body{}
75
+ .post_body p{}
76
+ .post_body p.source {}
77
+
78
+ ## Requirement
79
+
80
+ `Ruby 1.9.x or 2.x.x`
81
+
82
+ ## Contributing
83
+
84
+ No request is too small and I encourage everyone to get involved.
85
+
86
+ 1. Fork it
87
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
88
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
89
+ 4. Push to the branch (`git push origin my-new-feature`)
90
+ 5. Create new Pull Request
91
+
92
+ ## TODO
93
+
94
+ 1. Fix Options
95
+ 2. Add embed for 'answers'
96
+
97
+ ## Copyright
98
+
99
+ The Tumblr Client gem is Copyright (c) 2015 Richardson Dackam and is licensed under the MIT License.
100
+ Tumblr is Copyright (c) Tumblr, Inc. The Tumblr gem is NOT affiliated with Tumblr, Inc.
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => :spec
@@ -0,0 +1,24 @@
1
+ .post_content{
2
+ width: 700px;
3
+ padding: 20px;
4
+ }
5
+ .post_content .post_title{}
6
+ .post_content .post_title blockquote{
7
+ font: 100%/1.5 Avenir, Arial;
8
+ font-size: 1.5rem;
9
+
10
+ }
11
+ .post_content .extra_large{}
12
+
13
+ .post_body{
14
+ font: 100%/1.5 Avenir, Arial
15
+ }
16
+ .post_body p{
17
+ font-size: 1.2rem;
18
+ font: 100%/1.5 Avenir, Arial;
19
+ }
20
+
21
+ .post_body p.source {
22
+ text-align: right;
23
+ margin-right: 61px;
24
+ }
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tumblr_client_wrapper"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require 'tumblr_client_wrapper/version'
2
+
3
+ module TumblrClientWrapper
4
+ class Engine < Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ require 'tumblr_client_wrapper/posts'
2
+
3
+ module TumblrClientWrapper
4
+ module Helpers
5
+ include TumblrClientWrapper::Posts
6
+
7
+ def embed_tumblr(blog_id, options = {})
8
+ posts = embed_post(blog_id, options)
9
+ return posts.html_safe unless posts.empty?
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,246 @@
1
+ require 'tumblr_client'
2
+ require 'json'
3
+ module TumblrClientWrapper
4
+ module Posts
5
+
6
+ class ApiRequest
7
+
8
+ def initialize
9
+ @@tumblr_client = Tumblr::Client.new(client: :httpclient)
10
+ end
11
+
12
+ def get_posts(tumblr_id, options)
13
+ unless options.empty?
14
+ response = @@tumblr_client.posts("#{tumblr_id}.tumblr.com")
15
+ else
16
+ response = @@tumblr_client.posts("#{tumblr_id}.tumblr.com", options)
17
+ end
18
+ end
19
+
20
+ def paginate(tumbld_id, offset)
21
+ response = @@tumblr_client.posts("#{tumblr_id}.tumblr.com", offset: offset)
22
+ end
23
+ end
24
+
25
+ def embed_post(tumblr_id, options)
26
+ api = ApiRequest.new
27
+ posts = api.get_posts(tumblr_id, options)
28
+ embed = ""
29
+ if posts["posts"]
30
+ posts["posts"].each do |post|
31
+ post_type = post["type"]
32
+ case post_type
33
+ when "text"
34
+ embed += parse_text(post)
35
+ when "photo"
36
+ embed += parse_photo(post)
37
+ when "quote"
38
+ embed += parse_quote(post)
39
+ when "link"
40
+ embed += parse_link(post)
41
+ when "chat"
42
+ embed += parse_chat(post)
43
+ when "audio"
44
+ embed += parse_audio(post)
45
+ when "video"
46
+ embed += parse_video(post)
47
+ when "answer"
48
+ embed += parse_answer(post)
49
+ end
50
+ end
51
+ end
52
+ return embed
53
+ end
54
+
55
+ def parse_text(post)
56
+ title = post["title"]
57
+ body = post["body"]
58
+ date = post["date"]
59
+ embed = %Q(
60
+ <div class="post_content">
61
+ <div class="post_date">#{date}</div>
62
+ <div class="post_container">
63
+ <div class="post_title">
64
+ #{title}
65
+ </div>
66
+ <div class="post_body">
67
+ #{body}
68
+ </div>
69
+ </div>
70
+ </div>
71
+ )
72
+ end
73
+
74
+ def parse_photo(post)
75
+ caption = post["caption"]
76
+ link_url = post["link_url"]
77
+ photos = post["photos"]
78
+ date = post["date"]
79
+ photos_embed = ""
80
+ photos.each do |photo|
81
+ photos_embed = %Q(
82
+ <a href="#{link_url}">
83
+ <img src="#{photo["original_size"]["url"]}" width="#{photo["original_size"]["width"]}" height="#{photo["original_size"]["height"]}" alt="#{caption}">
84
+ </a>
85
+ )
86
+ end
87
+
88
+ embed = %Q(
89
+ <div class="post_content">
90
+ <div class="post_date">#{date}</div>
91
+ <div class="post_media">
92
+ #{photos_embed}
93
+ </div>
94
+ <div class="body">
95
+ #{caption}
96
+ </div>
97
+ </div>
98
+ )
99
+ end
100
+
101
+ def parse_quote(post)
102
+ content = post["text"]
103
+ source = post["source"]
104
+ date = post["date"]
105
+ embed = %Q(
106
+ <div class="post_content">
107
+ <div class="post_date">#{date}</div>
108
+ <div class="post_title extra_large">
109
+ <blockquote>
110
+ <p>#{content}</p>
111
+ </blockquote>
112
+ </div>
113
+ )
114
+ unless source.empty?
115
+ embed += %Q(
116
+ <div class="post_body">
117
+ <p class="source">- #{source}</p>
118
+ </div>
119
+ )
120
+ end
121
+ embed += %Q(
122
+ </div>
123
+ )
124
+ end
125
+
126
+ def parse_link(post)
127
+ title = post["title"]
128
+ url = post["url"]
129
+ author = post["author"]
130
+ excerpt = post["excerpt"]
131
+ publisher = post["publisher"]
132
+ photos = post["photos"]
133
+ description = post["description"]
134
+ date = post["date"]
135
+ embed = %Q(
136
+ <div class="post_content">
137
+ <div class="post_date">#{date}</div>
138
+ <div class="post_media">
139
+ <div class="link_button">
140
+ <a href="#" class="link_source_container">
141
+
142
+ </a>
143
+ </div>
144
+ </div>
145
+ <dvi class="post_body">
146
+ <p>#{description}</p>
147
+ </div>
148
+
149
+ </div>
150
+ )
151
+ end
152
+
153
+ def parse_chat(post)
154
+ title = post["title"]
155
+ body = post["body"]
156
+ dialogue = post["dialogue"]
157
+ date = post["date"]
158
+ embed = %Q(
159
+ <div class="post_content">
160
+ <div class="post_date">#{date}</div>
161
+ <div class="post_title">Post Tile"</div>
162
+ <div class="post_body">
163
+ <ul class="conversation_lines">
164
+ <li class="chat_line">
165
+ <strong></strong>
166
+
167
+ </li>
168
+ </ul>
169
+ </div>
170
+ </div>
171
+ )
172
+ end
173
+
174
+ def parse_audio(post)
175
+ if post[:type] == "audio"
176
+ source_url = post["source_url"]
177
+ source_title = post["source_title"]
178
+ id3_title = post["id3_title"]
179
+ caption = post["caption"]
180
+ player = post["player"]
181
+ plays = post["plays"]
182
+ date = post["date"]
183
+
184
+ embed = %Q(
185
+ <div class="post_content">
186
+ <div class="post_date">#{date}</div>
187
+ <div class="post_media" style="width: 540px; height: 304px;">
188
+ <iframe src="#{source_url}"></iframe>
189
+ </div>
190
+ <div class="post_body">
191
+ #{caption}
192
+ </div>
193
+ </div>
194
+ )
195
+ end
196
+ end
197
+
198
+ def parse_video(post)
199
+ source_url = post["source_url"]
200
+ source_title = post["source_title"]
201
+ caption = post["caption"]
202
+ player = post["player"]
203
+ date = post["date"]
204
+ embed = %Q(
205
+ <div class="post_content">
206
+ <div class="post_date">#{date}</div>
207
+ <div class="post_media" style="width: 540px; height: 304px;">
208
+ <iframe src="#{source_url}"></iframe>
209
+ </div>
210
+ <div class="post_body">
211
+ #{caption}
212
+ </div>
213
+ </div>
214
+ )
215
+ end
216
+
217
+ def parse_answer(post)
218
+ question = post["question"]
219
+ answer = post["answer"]
220
+ date = post["date"]
221
+ embed = %Q(
222
+ <div class="post_content">
223
+ <div class="post_date">#{date}</div>
224
+ <div class="post_container">
225
+ <div class="post_title">
226
+ #{question}
227
+ </div>
228
+ <div class="post_body">
229
+ #{answer}
230
+ </div>
231
+ </div>
232
+ </div>
233
+ )
234
+ end
235
+
236
+ module_function :parse_text,
237
+ :parse_photo,
238
+ :parse_quote,
239
+ :parse_link,
240
+ :parse_chat,
241
+ :parse_audio,
242
+ :parse_video,
243
+ :parse_answer
244
+
245
+ end
246
+ end
@@ -0,0 +1,9 @@
1
+ require 'tumblr_client_wrapper/helpers'
2
+
3
+ module TumblrClientWrapper
4
+ class Railtie < Rails::Railtie
5
+ initializer "tumblr_client_wrapper.helpers" do
6
+ ActionView::Base.send :include, Helpers
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module TumblrClientWrapper
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "tumblr_client_wrapper/version"
2
+ require 'tumblr_client_wrapper/engine'
3
+
4
+ module TumblrClientWrapper
5
+ require 'tumblr_client_wrapper/helpers'
6
+ require 'tumblr_client_wrapper/railtie' if defined?(Rails)
7
+ autoload :VERSION, File.join(File.dirname(__FILE__), 'tumblr_wrapper/version')
8
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tumblr_client_wrapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tumblr_client_wrapper"
8
+ spec.version = TumblrClientWrapper::VERSION
9
+ spec.authors = ["Richardson Dackam"]
10
+ spec.email = ["richardsondx@gmail.com"]
11
+
12
+ spec.summary = %q{Easily embed your tumblr posts on your rails appplication}
13
+ spec.description = %q{A Ruby wrapper for the Tumblr-client gem and Tumblr v2 API. The Tumblr-client-wrapper allow yout easily embed tumblr on your site}
14
+ spec.homepage = "http://github.com/richardsondx/tumblr_client_wrapper"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency 'rspec-rails', "~> 3.2", '>= 3.2.0'
33
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tumblr_client_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Richardson Dackam
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.2.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.2'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.2.0
61
+ description: A Ruby wrapper for the Tumblr-client gem and Tumblr v2 API. The Tumblr-client-wrapper
62
+ allow yout easily embed tumblr on your site
63
+ email:
64
+ - richardsondx@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - ".gitignore"
70
+ - ".travis.yml"
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - app/assets/stylesheets/tumblr_client_wrapper.css
76
+ - bin/console
77
+ - bin/setup
78
+ - lib/tumblr_client_wrapper.rb
79
+ - lib/tumblr_client_wrapper/engine.rb
80
+ - lib/tumblr_client_wrapper/helpers.rb
81
+ - lib/tumblr_client_wrapper/posts.rb
82
+ - lib/tumblr_client_wrapper/railtie.rb
83
+ - lib/tumblr_client_wrapper/version.rb
84
+ - tumblr_client_wrapper.gemspec
85
+ homepage: http://github.com/richardsondx/tumblr_client_wrapper
86
+ licenses:
87
+ - MIT
88
+ metadata:
89
+ allowed_push_host: https://rubygems.org
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Easily embed your tumblr posts on your rails appplication
110
+ test_files: []