posterous 0.2.1 → 0.2.2
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.
- data/README.md +144 -19
- data/bin/posterous +16 -10
- data/lib/posterous.rb +0 -23
- data/lib/posterous/association_proxy.rb +1 -1
- data/lib/posterous/inheritable.rb +1 -21
- data/lib/posterous/model.rb +16 -0
- data/lib/posterous/models/comment.rb +0 -1
- data/lib/posterous/models/external_site.rb +0 -1
- data/lib/posterous/models/like.rb +0 -1
- data/lib/posterous/models/link.rb +0 -1
- data/lib/posterous/models/link_category.rb +0 -1
- data/lib/posterous/models/page.rb +0 -1
- data/lib/posterous/models/post.rb +0 -1
- data/lib/posterous/models/profile.rb +0 -1
- data/lib/posterous/models/subscriber.rb +0 -1
- data/lib/posterous/models/subscription.rb +0 -1
- data/lib/posterous/models/tag.rb +0 -1
- data/lib/posterous/version.rb +1 -1
- metadata +3 -3
    
        data/README.md
    CHANGED
    
    | @@ -1,31 +1,156 @@ | |
| 1 1 | 
             
            # Posterous #
         | 
| 2 2 |  | 
| 3 | 
            +
            ## Dependencies ##
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              Typhoeus [https://github.com/dbalatero/typhoeus](https://github.com/dbalatero/typhoeus)
         | 
| 6 | 
            +
             | 
| 3 7 | 
             
            ## Installation ##
         | 
| 4 8 |  | 
| 5 9 | 
             
                gem install posterous
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ## Rails ##
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              In you Gemfile:
         | 
| 14 | 
            +
              
         | 
| 15 | 
            +
                gem 'posterous'
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              Create `config/initializers/posterous.rb`.
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ```ruby
         | 
| 20 | 
            +
            Posterous.config = {
         | 
| 21 | 
            +
              'username'  => '<username>',
         | 
| 22 | 
            +
              'password'  => '<password>',
         | 
| 23 | 
            +
              'api_token' => '<api_token>'
         | 
| 24 | 
            +
            }
         | 
| 25 | 
            +
            ```
         | 
| 6 26 |  | 
| 7 | 
            -
            ##  | 
| 8 | 
            -
                
         | 
| 9 | 
            -
                require 'posterous'
         | 
| 10 | 
            -
                
         | 
| 11 | 
            -
                Posterous.config = {
         | 
| 12 | 
            -
                  'username' => <username>,
         | 
| 13 | 
            -
                  'password' => <password>,
         | 
| 14 | 
            -
                  'api_token' => '<api_token>'
         | 
| 15 | 
            -
                }
         | 
| 16 | 
            -
                
         | 
| 17 | 
            -
                include Posterous
         | 
| 27 | 
            +
            ## Elsewhere ##
         | 
| 18 28 |  | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 29 | 
            +
            ```ruby
         | 
| 30 | 
            +
            require 'posterous'
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            Posterous.config = {
         | 
| 33 | 
            +
              'username'  => '<username>',
         | 
| 34 | 
            +
              'password'  => '<password>',
         | 
| 35 | 
            +
              'api_token' => '<api_token>'
         | 
| 36 | 
            +
            }
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            include Posterous
         | 
| 39 | 
            +
            ```
         | 
| 40 | 
            +
             | 
| 41 | 
            +
             | 
| 42 | 
            +
            ## API ##
         | 
| 43 | 
            +
             | 
| 44 | 
            +
            ## User ##
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              **Current user info**
         | 
| 47 | 
            +
              
         | 
| 48 | 
            +
                > User.me
         | 
| 49 | 
            +
                => <#<Posterous::User:0x00000100cacbe0> {:last_activity=>"2011/04/25 20:33:50 -0700",
         | 
| 50 | 
            +
                :nickname=>"postertester", :lastname=>nil, :id=>1288737, :firstname=>nil, 
         | 
| 51 | 
            +
                :profile_pic=>"http://posterous.com/images/profile/unknown75.gif"}>
         | 
| 52 | 
            +
              
         | 
| 53 | 
            +
              **Favorites**
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                > @user = User.me
         | 
| 56 | 
            +
                > @user.favorites(:page => 1)
         | 
| 57 | 
            +
                => [<#<Posterous::Post:0x00000100c2c7b0>...] 
         | 
| 58 | 
            +
             | 
| 59 | 
            +
              **Subscriptions**
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                > @user = User.me
         | 
| 62 | 
            +
                > @user.subscriptions(:page => 1)
         | 
| 63 | 
            +
                => [<#<Posterous::Site:0x00000100c2c7b0>...] 
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              **Subscription Posts**
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                > @user = User.me
         | 
| 68 | 
            +
                > @user.subscriptions.posts(:page => 1)
         | 
| 69 | 
            +
                => [<#<Posterous::Post:0x00000100c2c7b0>...] 
         | 
| 70 | 
            +
             | 
| 71 | 
            +
            ## Sites ##
         | 
| 72 | 
            +
             | 
| 73 | 
            +
              **Find a primary site**
         | 
| 74 | 
            +
              
         | 
| 75 | 
            +
                > Site.primary
         | 
| 76 | 
            +
                => <#<Posterous::Site:0x00000100c22490> {:header_image=>nil, :name=>"postertester's posterous" ... }>
         | 
| 23 77 |  | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
                 | 
| 78 | 
            +
              **Find a Site by its hostname**
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                > Site.find('twoism')
         | 
| 81 | 
            +
                => <#<Posterous::Site:0x00000100c22490> {:header_image=>nil, :name=>"postertester's posterous" ... }>
         | 
| 82 | 
            +
             | 
| 83 | 
            +
              **Find all of the current user's Sites**
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                > Site.all(:page => 1)
         | 
| 86 | 
            +
                => [<#<Posterous::Site:0x00000100c22490> {:header_image=>nil, :name=>"postertester's posterous" ... }>]
         | 
| 87 | 
            +
             | 
| 88 | 
            +
              **Creating a new Site**
         | 
| 27 89 |  | 
| 90 | 
            +
                > @site = Site.create(:hostname => 'superawesome',:is_private => false)
         | 
| 91 | 
            +
                => <#<Posterous::Site:0x00000100c22490> {:header_image=>nil, :name=>"superawesome's posterous" ... }>
         | 
| 92 | 
            +
             | 
| 93 | 
            +
              **Updating a Site**
         | 
| 28 94 |  | 
| 95 | 
            +
                > @site = Site.primary
         | 
| 96 | 
            +
                => @site.hostname = 'anotherawesomesite'
         | 
| 97 | 
            +
                => @site.save
         | 
| 98 | 
            +
             | 
| 99 | 
            +
              **Deleting a Site**
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                > @site = Site.find('sitetodelete')
         | 
| 102 | 
            +
                => @site.destroy
         | 
| 103 | 
            +
             | 
| 104 | 
            +
             | 
| 105 | 
            +
            ## Posts ##
         | 
| 106 | 
            +
             | 
| 107 | 
            +
              **Creating Posts**
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                > @site = Site.primary
         | 
| 110 | 
            +
                > @post = @site.posts.create(:title => 'New Post', :body => 'From posterous API', 
         | 
| 111 | 
            +
                :media => [File.open('/path/to/file')], :autopost => true)
         | 
| 112 | 
            +
                => <#<Posterous::Post:0x00000100c2c7b0>
         | 
| 113 | 
            +
             | 
| 114 | 
            +
              **Updating Posts**
         | 
| 115 | 
            +
              
         | 
| 116 | 
            +
                > @post = @site.posts.find(<id>)
         | 
| 117 | 
            +
                > @post.title = 'Kittens are radical!'
         | 
| 118 | 
            +
                > @post.save
         | 
| 119 | 
            +
             | 
| 120 | 
            +
              **Deleting Posts**
         | 
| 121 | 
            +
              
         | 
| 122 | 
            +
                > @post = @site.posts.find(<id>)
         | 
| 123 | 
            +
                > @post.destroy
         | 
| 124 | 
            +
             | 
| 125 | 
            +
              **Retrieving Posts**
         | 
| 126 | 
            +
             | 
| 127 | 
            +
                # paginated
         | 
| 128 | 
            +
                > @site.posts(:page => 1)
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                # paginated since a given id
         | 
| 131 | 
            +
                > @site.posts(:page => 3, :since_id => 123)
         | 
| 132 | 
            +
             | 
| 133 | 
            +
            ## Commenting ##
         | 
| 134 | 
            +
             | 
| 135 | 
            +
                > @site = Site.find('someawesomesite')
         | 
| 136 | 
            +
                > @site.posts.first.comments.create(:body => "Yes, kittens are very
         | 
| 137 | 
            +
                > radical")
         | 
| 138 | 
            +
             | 
| 139 | 
            +
            ## Liking ##
         | 
| 140 | 
            +
             | 
| 141 | 
            +
                > @site = Site.find('someawesomesite')
         | 
| 142 | 
            +
                > @site.posts.first.likes.create
         | 
| 143 | 
            +
             | 
| 144 | 
            +
            ## Subscribers ##
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                > @site = Site.find('someawesomesite')
         | 
| 147 | 
            +
                > @site.subscribers(:page => 1)
         | 
| 148 | 
            +
             | 
| 149 | 
            +
            ## External Sites / Autopost ##
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                > @site.external_sites(:page => 1)
         | 
| 152 | 
            +
                => [<#<Posterous::ExternalSite:0x00000100c2c7b0>]
         | 
| 153 | 
            +
             | 
| 29 154 | 
             
            ## Interactive Console Usage ##
         | 
| 30 155 |  | 
| 31 156 | 
             
              In your terminal type...
         | 
| @@ -62,4 +187,4 @@ | |
| 62 187 | 
             
                 => <#<Posterous::Post:0x00000101398670> 
         | 
| 63 188 | 
             
                > post.comments.create(:body => 'Kittens are radical!')
         | 
| 64 189 | 
             
                => <#<Posterous::Comment:0x0000010135f758> ... }>
         | 
| 65 | 
            -
                
         | 
| 190 | 
            +
                
         | 
    
        data/bin/posterous
    CHANGED
    
    | @@ -37,12 +37,8 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') | |
| 37 37 |  | 
| 38 38 | 
             
            %w{posterous irb}.each { |f| require f }
         | 
| 39 39 |  | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
              yml = YAML.load_file(RC_PATH)
         | 
| 43 | 
            -
            else
         | 
| 44 | 
            -
              rc = File.open(RC_PATH, 'w')
         | 
| 45 | 
            -
            end
         | 
| 40 | 
            +
            rc  = File.exists?(RC_PATH) ? File.open(RC_PATH, 'r') : File.open(RC_PATH, 'w')
         | 
| 41 | 
            +
            yml = YAML.load_file(RC_PATH)
         | 
| 46 42 |  | 
| 47 43 | 
             
            if yml.is_a?(Hash)
         | 
| 48 44 | 
             
              cfg = yml
         | 
| @@ -50,22 +46,32 @@ else | |
| 50 46 | 
             
              cfg = {}
         | 
| 51 47 | 
             
              puts "Email Address:"
         | 
| 52 48 | 
             
              cfg['username'] = gets.chomp
         | 
| 53 | 
            -
               | 
| 54 | 
            -
             | 
| 49 | 
            +
              begin
         | 
| 50 | 
            +
                puts "Password:"
         | 
| 51 | 
            +
                system('stty -echo')
         | 
| 52 | 
            +
                cfg['password'] = gets.chomp
         | 
| 53 | 
            +
              rescue
         | 
| 54 | 
            +
              ensure
         | 
| 55 | 
            +
                system('stty echo')
         | 
| 56 | 
            +
              end
         | 
| 55 57 | 
             
              puts "Api Token:"
         | 
| 56 58 | 
             
              cfg['api_token'] = gets.chomp
         | 
| 57 59 | 
             
              rc.puts cfg.to_yaml
         | 
| 58 60 | 
             
            end
         | 
| 59 61 |  | 
| 62 | 
            +
            rc.puts cfg.to_yaml
         | 
| 60 63 | 
             
            rc.close
         | 
| 61 64 |  | 
| 62 65 | 
             
            Posterous.config = cfg
         | 
| 63 66 |  | 
| 64 67 | 
             
            include Posterous
         | 
| 65 68 |  | 
| 66 | 
            -
             | 
| 69 | 
            +
            def current_user
         | 
| 70 | 
            +
              @current_user ||= User.me
         | 
| 71 | 
            +
            end
         | 
| 72 | 
            +
             | 
| 67 73 | 
             
            puts "*"*100
         | 
| 68 | 
            -
            puts "Hi #{ | 
| 74 | 
            +
            puts "Hi #{current_user.nickname}, welcome to the Posterous API Console! For help type `newb`.\n"
         | 
| 69 75 | 
             
            puts "*"*100
         | 
| 70 76 |  | 
| 71 77 | 
             
            IRB.setup(nil)
         | 
    
        data/lib/posterous.rb
    CHANGED
    
    | @@ -1,28 +1,5 @@ | |
| 1 1 | 
             
            %w[typhoeus yaml json ostruct].each { |lib| require lib }
         | 
| 2 2 |  | 
| 3 | 
            -
            require 'pathname'
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            dir = Pathname(__FILE__).dirname.expand_path
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            require dir + 'posterous/connection'
         | 
| 8 | 
            -
            require dir + 'posterous/inheritable'
         | 
| 9 | 
            -
            require dir + 'posterous/model'
         | 
| 10 | 
            -
            require dir + 'posterous/models/tag'
         | 
| 11 | 
            -
            require dir + 'posterous/models/subscriber'
         | 
| 12 | 
            -
            require dir + 'posterous/models/subscription'
         | 
| 13 | 
            -
            require dir + 'posterous/models/comment'
         | 
| 14 | 
            -
            require dir + 'posterous/models/like'
         | 
| 15 | 
            -
            require dir + 'posterous/models/post'
         | 
| 16 | 
            -
            require dir + 'posterous/models/page'
         | 
| 17 | 
            -
            require dir + 'posterous/models/link'
         | 
| 18 | 
            -
            require dir + 'posterous/models/link_category'
         | 
| 19 | 
            -
            require dir + 'posterous/models/external_site'
         | 
| 20 | 
            -
            require dir + 'posterous/models/user'
         | 
| 21 | 
            -
            require dir + 'posterous/models/profile'
         | 
| 22 | 
            -
            require dir + 'posterous/models/site'
         | 
| 23 | 
            -
            require dir + 'posterous/association_proxy'
         | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 3 | 
             
            module Posterous
         | 
| 27 4 | 
             
              BASE_API_URL = 'http://posterous.com/api/v2'
         | 
| 28 5 |  | 
| @@ -9,7 +9,7 @@ module Posterous | |
| 9 9 | 
             
                  @proxied            = proxied
         | 
| 10 10 | 
             
                  @association        = nil
         | 
| 11 11 |  | 
| 12 | 
            -
                  @association_klass.finder_opts[klass. | 
| 12 | 
            +
                  @association_klass.finder_opts[klass.resource_url_keys.last] = proxied.id
         | 
| 13 13 | 
             
                  @association_klass.finder_opts.merge!(@proxied.finder_opts)
         | 
| 14 14 |  | 
| 15 15 | 
             
                  load_method   =  association_type == :many ? :all : :load
         | 
| @@ -6,7 +6,7 @@ module Posterous | |
| 6 6 | 
             
                    extend ClassMethods
         | 
| 7 7 | 
             
                    include InstanceMethods
         | 
| 8 8 |  | 
| 9 | 
            -
                    inherited_attributes :finder_opts, : | 
| 9 | 
            +
                    inherited_attributes :finder_opts, :resource_path
         | 
| 10 10 | 
             
                    @finder_opts ||= {} 
         | 
| 11 11 | 
             
                  end  
         | 
| 12 12 | 
             
                end
         | 
| @@ -34,32 +34,12 @@ module Posterous | |
| 34 34 | 
             
                    @resource_path = path
         | 
| 35 35 | 
             
                  end
         | 
| 36 36 |  | 
| 37 | 
            -
                  def parent sym
         | 
| 38 | 
            -
                    @parent_resource = sym
         | 
| 39 | 
            -
                  end
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                  def many collection_name, klass
         | 
| 42 | 
            -
                    define_method collection_name do |*args|
         | 
| 43 | 
            -
                      AssociationProxy.new self, klass, :many, *args
         | 
| 44 | 
            -
                    end
         | 
| 45 | 
            -
                  end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                  def one collection_name, klass
         | 
| 48 | 
            -
                    define_method collection_name do |*args|
         | 
| 49 | 
            -
                      AssociationProxy.new self, klass, :one, *args
         | 
| 50 | 
            -
                    end
         | 
| 51 | 
            -
                  end
         | 
| 52 | 
            -
             | 
| 53 37 | 
             
                end
         | 
| 54 38 |  | 
| 55 39 | 
             
                module InstanceMethods
         | 
| 56 40 | 
             
                  def resource_path
         | 
| 57 41 | 
             
                    self.class.resource_path
         | 
| 58 42 | 
             
                  end
         | 
| 59 | 
            -
             | 
| 60 | 
            -
                  def parent_resource
         | 
| 61 | 
            -
                    self.class.parent_resource
         | 
| 62 | 
            -
                  end
         | 
| 63 43 |  | 
| 64 44 | 
             
                  def finder_opts
         | 
| 65 45 | 
             
                    self.class.finder_opts
         | 
    
        data/lib/posterous/model.rb
    CHANGED
    
    | @@ -4,6 +4,18 @@ module Posterous | |
| 4 4 | 
             
                extend Connection
         | 
| 5 5 |  | 
| 6 6 | 
             
                attr_reader :struct
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def self.many collection_name, klass
         | 
| 9 | 
            +
                  define_method collection_name do |*args|
         | 
| 10 | 
            +
                    AssociationProxy.new self, klass, :many, *args
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def self.one collection_name, klass
         | 
| 15 | 
            +
                  define_method collection_name do |*args|
         | 
| 16 | 
            +
                    AssociationProxy.new self, klass, :one, *args
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 7 19 |  | 
| 8 20 | 
             
                # hack for ruby 1.8.7 
         | 
| 9 21 | 
             
                def id
         | 
| @@ -87,6 +99,10 @@ module Posterous | |
| 87 99 | 
             
                def parsed_resource_url
         | 
| 88 100 | 
             
                  self.class.parsed_resource_url     
         | 
| 89 101 | 
             
                end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                def self.resource_url_keys
         | 
| 104 | 
            +
                  resource_path.scan(/:(\w+)/).flatten.collect(&:to_sym)
         | 
| 105 | 
            +
                end
         | 
| 90 106 |  | 
| 91 107 | 
             
                def initialize struct
         | 
| 92 108 | 
             
                  @struct = struct
         | 
    
        data/lib/posterous/models/tag.rb
    CHANGED
    
    
    
        data/lib/posterous/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version | |
| 5 5 | 
             
              segments: 
         | 
| 6 6 | 
             
              - 0
         | 
| 7 7 | 
             
              - 2
         | 
| 8 | 
            -
              -  | 
| 9 | 
            -
              version: 0.2. | 
| 8 | 
            +
              - 2
         | 
| 9 | 
            +
              version: 0.2.2
         | 
| 10 10 | 
             
            platform: ruby
         | 
| 11 11 | 
             
            authors: 
         | 
| 12 12 | 
             
            - Christopher Burnett @twoism
         | 
| @@ -14,7 +14,7 @@ autorequire: | |
| 14 14 | 
             
            bindir: bin
         | 
| 15 15 | 
             
            cert_chain: []
         | 
| 16 16 |  | 
| 17 | 
            -
            date: 2011-04- | 
| 17 | 
            +
            date: 2011-04-26 00:00:00 -07:00
         | 
| 18 18 | 
             
            default_executable: 
         | 
| 19 19 | 
             
            dependencies: 
         | 
| 20 20 | 
             
            - !ruby/object:Gem::Dependency 
         |