Class: LivedoorBlog
- Inherits:
-
Object
- Object
- LivedoorBlog
- Defined in:
- lib/livedoor_blog.rb,
lib/livedoor_blog/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Method Summary collapse
- #create_folder(name) ⇒ Object
- #folder_list ⇒ Object
-
#initialize ⇒ LivedoorBlog
constructor
A new instance of LivedoorBlog.
- #login(livedoor_id, password) ⇒ Object
- #submit_entry(title, body) ⇒ Object
- #upload_image(image_file, folder = nil) ⇒ Object
Constructor Details
#initialize ⇒ LivedoorBlog
Returns a new instance of LivedoorBlog.
8 9 10 11 12 13 14 |
# File 'lib/livedoor_blog.rb', line 8 def initialize @logger = Logger.new(STDERR) @logger.level = Logger::INFO @a = Mechanize.new @a.user_agent_alias = "Linux Firefox" end |
Instance Method Details
#create_folder(name) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/livedoor_blog.rb', line 47 def create_folder(name) page = @a.post("http://livedoor.blogcms.jp/blog/#{@livedoor_id}/file/folder/api/add", { :name => name, :rkey => @rkey, }) JSON.parse(page.body) end |
#folder_list ⇒ Object
55 56 57 58 59 |
# File 'lib/livedoor_blog.rb', line 55 def folder_list page = @a.get("http://livedoor.blogcms.jp/blog/#{@livedoor_id}/file/folder/api/folders_pager") h = JSON.parse(page.body) h["entries"] end |
#login(livedoor_id, password) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/livedoor_blog.rb', line 16 def login(livedoor_id, password) @livedoor_id = livedoor_id @password = password get("https://member.livedoor.com/login/?.sv=top") submit('loginForm', 'livedoor_id' => @livedoor_id, 'password' => @password) @rkey = get_rkey end |
#submit_entry(title, body) ⇒ Object
41 42 43 44 45 |
# File 'lib/livedoor_blog.rb', line 41 def submit_entry(title, body) click('ブログを書く') click('記事を書く') submit('ArticleForm', 'body' => body, 'title' => title) end |
#upload_image(image_file, folder = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/livedoor_blog.rb', line 25 def upload_image(image_file, folder = nil) @logger.info("uploading #{image_file}") folder_id = nil if folder folder_id = folder_list.detect{|x| x["name"] == folder }["id"] end @logger.info("folder_id: #{folder_id}") File.open(image_file){|f| res = @a.post("http://livedoor.blogcms.jp/livedoor/#{@livedoor_id}/file/image/multi_upload", {:rkey => @rkey, 'file_1' => f, 'folder_1' => folder_id}) @logger.debug(res.body) JSON.parse(res.body)["result"].first["image_url"] } end |