# Hatenablog [![Gem Version](https://badge.fury.io/rb/hatenablog.svg)](https://badge.fury.io/rb/hatenablog) [![Build Status](https://travis-ci.org/kymmt90/hatenablog.svg?branch=master)](https://travis-ci.org/kymmt90/hatenablog) [![Code Climate](https://codeclimate.com/github/kymmt90/hatenablog/badges/gpa.svg)](https://codeclimate.com/github/kymmt90/hatenablog) [![Test Coverage](https://codeclimate.com/github/kymmt90/hatenablog/badges/coverage.svg)](https://codeclimate.com/github/kymmt90/hatenablog/coverage) A library for Hatenablog AtomPub API. This gem supports following operations using OAuth authorization: - 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 keys and tokens 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](http://developer.hatena.ne.jp/) and get your application consumer key. #### 2. Get your access token and access token secret Execute this command: $ get_access_token Visit this website and get the PIN: https://www.hatena.com/oauth/authorize?oauth_token=XXXXXXXXXXXXXXXXXXXX Enter the PIN: [Enter] Access token: Access token secret: #### 3. Set up the YAML configuration file The default configuration file name is `config.yml`: ```yml consumer_key: consumer_secret: access_token: access_token_secret: user_id: blog_id: ``` This file accepts ERB syntax. ```yml 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'] %> ``` ## Usage ```ruby require 'hatenablog' # Read the OAuth 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 ```