All Projects → kymmt90 → hatenablog

kymmt90 / hatenablog

Licence: MIT license
A Ruby gem for Hatena Blog AtomPub API

Programming Languages

ruby
36898 projects - #4 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to hatenablog

rarbg
Ruby client for the RARBG Torrent API.
Stars: ✭ 17 (-57.5%)
Mutual labels:  ruby-gem, ruby-client
dokken-images
Minimal Docker Images for testing
Stars: ✭ 20 (-50%)
Mutual labels:  ruby-gem
No Style Please
A (nearly) no-CSS, fast, minimalist Jekyll theme.
Stars: ✭ 192 (+380%)
Mutual labels:  ruby-gem
Api Fuzzer
API Fuzzer which allows to fuzz request attributes using common pentesting techniques and lists vulnerabilities
Stars: ✭ 238 (+495%)
Mutual labels:  ruby-gem
Tty
Toolkit for developing sleek command line apps.
Stars: ✭ 2,329 (+5722.5%)
Mutual labels:  ruby-gem
gcra-ruby
Generic cell rate algorithm (leaky bucket) implementation for rate limiting
Stars: ✭ 49 (+22.5%)
Mutual labels:  ruby-gem
Tty Table
A flexible and intuitive table generator
Stars: ✭ 161 (+302.5%)
Mutual labels:  ruby-gem
jekyll-extlinks
This Jekyll plugin adds custom attributes (rel="nofollow", target="_blank", etc.) to external links in your content.
Stars: ✭ 18 (-55%)
Mutual labels:  ruby-gem
stackup
a simple CLI and Ruby API for AWS CloudFormation
Stars: ✭ 89 (+122.5%)
Mutual labels:  ruby-gem
Unimidi
Realtime MIDI IO for Ruby
Stars: ✭ 229 (+472.5%)
Mutual labels:  ruby-gem
Caxlsx
xlsx generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine.
Stars: ✭ 221 (+452.5%)
Mutual labels:  ruby-gem
Email address
The EmailAddress Gem to work with and validate email addresses.
Stars: ✭ 199 (+397.5%)
Mutual labels:  ruby-gem
crate ruby
A Ruby client library for CrateDB.
Stars: ✭ 31 (-22.5%)
Mutual labels:  ruby-gem
Discogs
A Ruby wrapper of the Discogs.com API
Stars: ✭ 195 (+387.5%)
Mutual labels:  ruby-gem
memo wise
The wise choice for Ruby memoization
Stars: ✭ 486 (+1115%)
Mutual labels:  ruby-gem
Oscailte
Oscailte — A powerful light, clean, and responsive Jekyll theme.
Stars: ✭ 178 (+345%)
Mutual labels:  ruby-gem
Filestack Rails
Official Ruby on Rails plugin for Filestack File Picker that makes it easy to add powerful file uploading and transformation capabilities to any web or mobile application.
Stars: ✭ 220 (+450%)
Mutual labels:  ruby-gem
Dry Schema
Coercion and validation for data structures
Stars: ✭ 249 (+522.5%)
Mutual labels:  ruby-gem
glimmer-dsl-opal
Glimmer DSL for Opal (Pure-Ruby Web GUI and Auto-Webifier of Desktop Apps)
Stars: ✭ 22 (-45%)
Mutual labels:  ruby-gem
tty-platform
Operating system detection
Stars: ✭ 28 (-30%)
Mutual labels:  ruby-gem

Hatenablog

Gem Version Build Status Code Climate Test Coverage

A library for Hatena Blog AtomPub API

This gem supports following operations through OAuth 1.0a or Basic authentication:

  • Get blog feeds, entries and categories
  • Post blog entries
  • Update blog entries
  • Delete blog entries

Installation

Install the gem

Add this line to your application's Gemfile:

gem 'hatenablog'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hatenablog

Get OAuth credentials

You need to set up OAuth 1.0a keys and tokens before using this gem.

1. Get consumer key and consumer key secret

Access Hatena application registoration page and get your application consumer key.

2. Get your access token and access token secret

Execute this command:

$ get_hatena_oauth_access_token <your consumer key> <your consumer secret>
Visit this website and get the PIN: https://www.hatena.com/oauth/authorize?oauth_token=XXXXXXXXXXXXXXXXXXXX
Enter the PIN: <your PIN> [Enter]
Access token: <your access token>
Access token secret: <your access token secret>

3. [Optional] Set up the YAML configuration file

The default configuration file name is config.yml:

consumer_key: <Hatena application consumer key>
consumer_secret: <Hatena application consumer secret>
access_token: <Hatena application access token>
access_token_secret: <Hatena application access token secret>
user_id: <Hatena user ID>
blog_id: <Hatenablog ID>

This file accepts ERB syntax.

consumer_key: <%= ENV['CONSUMER_KEY'] %>
consumer_secret: <%= ENV['CONSUMER_SECRET'] %>
access_token: <%= ENV['ACCESS_TOKEN'] %>
access_token_secret: <%= ENV['ACCESS_TOKEN_SECRET'] %>
user_id: <%= ENV['USER_ID'] %>
blog_id: <%= ENV['BLOG_ID'] %>

blog_id means your Hatena Blog domain, like "example-user.hatenablog.com".

You also can set these configurations in your code as described in the below section.

[Optional] Get Basic authentication credentials

If you want to use Basic authentication, visit http://blog.hatena.ne.jp/#{user_id}/#{blog_id}/config/detail and check your API key and set up config.yml like the following.

auth_type: basic
api_key: <%= ENV['API_KEY'] %>
user_id: <%= ENV['USER_ID'] %>
blog_id: <%= ENV['BLOG_ID'] %>

Usage

require 'hatenablog'

# Read the configuration from 'config.yml'
Hatenablog::Client.create do |blog|
  # Get each entry's content
  blog.entries.each do |entry|
    puts entry.content
  end

  # Post new entry
  posted_entry = blog.post_entry(
    'Entry Title',
    'This is entry contents', # markdown form
    ['Test', 'Programming']   # categories
  )

  # Update entry
  updated_entry = blog.update_entry(
    posted_entry.id,
    'Revised Entry Title',
    posted_entry.content,
    posted_entry.categories
  )

  # Delete entry
  blog.delete_entry(updated_entry.id)
end

API

Factories

You can create the client from the configuration file.

# Create the client from "./config.yml"
client = Hatenablog::Client.create

# Create the client from the specified configuration
client = Hatenablog::Client.create('../another_config.yml')

Hatenablog::Client.create do |client|
  # Use the client in the block
end

You can also create the client with a block for configurations.

client = Hatenablog::Client.new do |config|
  config.consumer_key        = 'XXXXXXXXXXXXXXXXXXXX'
  config.consumer_secret     = 'XXXXXXXXXXXXXXXXXXXX'
  config.access_token        = 'XXXXXXXXXXXXXXXXXXXX'
  config.access_token_secret = 'XXXXXXXXXXXXXXXXXXXX'
  config.user_id             = 'example-user'
  config.blog_id             = 'example-user.hatenablog.com'
end

Blog

client.title       # Get the blog title
client.author_name # Get the blog author name

Feeds

feed = client.next_feed # Get the first feed when no argument is passed
feed.uri
feed.next_uri    # The next feed URI
feed.title
feed.author_name
feed.updated     # Updated datetime

feed.entries # entries in the feed
feed.each_entry do |entry|
  # ...
end
feed.has_next? # true if the next page exists
next_feed = client.next_feed(feed)

Entries

client.get_entry('0000000000000000000') # Get the entry specifed by its ID
client.entries     # Get blog entries in the first page
client.entries(1)  # Get blog entries in the first and the second page
client.all_entries # Get all entries in the blog

entry = client.post_entry(
  'Example Title',                  # title
  'This is the **example** entry.', # content
  ['Ruby', 'Rails'],                # categories
  'yes',                            # draft
  '2022-04-11T15:43:20+09:00'       # updated
)
entry.id
entry.uri
entry.edit_uri
entry.author_name
entry.title             #=> 'Example Title'
entry.content           #=> 'This is the **example** entry.'
entry.formatted_content #=> '<p>This is the <strong>example</strong> entry.</p>'
entry.draft             #=> 'yes'
entry.draft?            #=> true
entry.categories        #=> ['Ruby', 'Rails']
entry.updated           # Updated datetime

client.update_entry(
  entry.id,
  entry.title,
  'This is the **modified** example entry.',
  entry.categories,
  'no'
)
client.delete_entry(entry.id)

Categories

categories = client.categories # Get categories registered in the blog
categories.each do |cat|
  puts cat
end

# When categories are fixed, you can only use those categories for your entries.
# ref: https://tools.ietf.org/html/rfc5023#section-7.2.1.1
categories.fixed?

Contributing

  1. Create your feature branch (git checkout -b my-new-feature)
  2. Commit your changes (git commit -am 'Add some feature')
  3. Push to the branch (git push origin my-new-feature)
  4. Create a new Pull Request

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].