posterous-gem
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:Ruby client for the Posterous API
# Posterous #

## Dependencies ##

  Typhoeus [https://github.com/dbalatero/typhoeus](https://github.com/dbalatero/typhoeus)

## Installation ##

    gem install posterous

## Rails ##

  In your Gemfile:
  
    gem 'posterous'

  Create `config/initializers/posterous.rb`.

```ruby
Posterous.config = {
  'username'  => '',
  'password'  => '',
  'api_token' => ''
}
```

## A note on rate limits ##

By default the gem will wait one second per api request. However, if you have a whitelisted 
token, you can pass ```'limit' => false``` in Posterous.config like so:


```ruby
Posterous.config = {
  'username'  => '',
  'password'  => '',
  'api_token' => ''
  'limit'     => false
}
```

## Elsewhere ##
    
```ruby
require 'posterous'

Posterous.config = {
  'username'  => '',
  'password'  => '',
  'api_token' => ''
}

include Posterous
```


## API ##

## User ##

  **Current user info**
  
    > User.me
    => <# {:last_activity=>"2011/04/25 20:33:50 -0700",
    :nickname=>"postertester", :lastname=>nil, :id=>1288737, :firstname=>nil, 
    :profile_pic=>"http://posterous.com/images/profile/unknown75.gif"}>
  
  **Favorites**

    > @user = User.me
    > @user.favorites(:page => 1)
    => [<#...] 

  **Subscriptions**

    > @user = User.me
    > @user.subscriptions(:page => 1)
    => [<#...] 

  **Subscription Posts**

    > @user = User.me
    > @user.subscriptions.posts(:page => 1)
    => [<#...] 

## Sites ##

  **Find a primary site**
  
    > Site.primary
    => <# {:header_image=>nil, :name=>"postertester's posterous" ... }>
    
  **Find a Site by its hostname**

    > Site.find('twoism')
    => <# {:header_image=>nil, :name=>"postertester's posterous" ... }>

  **Find all of the current user's Sites**

    > Site.all(:page => 1)
    => [<# {:header_image=>nil, :name=>"postertester's posterous" ... }>]

  **Creating a new Site**

    > @site = Site.create(:hostname => 'superawesome',:is_private => false)
    => <# {:header_image=>nil, :name=>"superawesome's posterous" ... }>

  **Updating a Site**
    
    > @site = Site.primary
    => @site.hostname = 'anotherawesomesite'
    => @site.save

  **Deleting a Site**

    > @site = Site.find('sitetodelete')
    => @site.destroy


## Posts ##

  **Creating Posts**

    > @site = Site.primary
    > @post = @site.posts.create(:title => 'New Post', :body => 'From posterous API', 
    :media => [File.open('/path/to/file')], :autopost => true)
    => <#

  **Updating Posts**
  
    > @post = @site.posts.find()
    > @post.title = 'Kittens are radical!'
    > @post.save

  **Deleting Posts**
  
    > @post = @site.posts.find()
    > @post.destroy

  **Retrieving Posts**

    # paginated
    > @site.posts(:page => 1)

    # paginated since a given id
    > @site.posts(:page => 3, :since_id => 123)

## Commenting ##

    > @site = Site.find('someawesomesite')
    > @site.posts.first.comments.create(:body => "Yes, kittens are very
    > radical")

## Liking ##

    > @site = Site.find('someawesomesite')
    > @site.posts.first.likes.create

## Subscribers ##

    > @site = Site.find('someawesomesite')
    > @site.subscribers(:page => 1)

## External Sites / Autopost ##

    > @site.external_sites(:page => 1)
    => [<#]

## Interactive Console Usage ##

  In your terminal type...
  
    $ posterous
    
  You will then be walked through the setup process. Type `newb` to get some help.
    
    ****************************************************************************************************
    Hi , welcome to the Posterous API Console! For help type `newb`.
    ****************************************************************************************************
    > newb
    
    # Get your primary site
    > Site.primary
    => <# ... }>

    # Get all your sites
    > Site.all
    => [<# ... }>]

    # Get any public site
    > Site.find('twoism')
    => <# ... }>

    # Get some posts
    > s = Site.primary
    > s.posts(:page => 1)
    => [<# ... }>]

    # Create a post and add a comment to it
    > s = Site.primary
    > post = s.posts.create(:title => 'Woo Hoo!')
     => <# 
    > post.comments.create(:body => 'Kittens are radical!')
    => <# ... }>
    

本源码包内暂不包含可直接显示的源代码文件,请下载源码包。