Sha256: 94d0d20b1aa26ef0905be1d874b384b32a3aebfa42b14ac04f68d7d2a1bf2aa6

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

RestCore::Mixi = RestCore::Builder.client(
  :data, :consumer_key, :consumer_secret, :redirect_uri) do
  s = self.class # this is only for ruby 1.8!
  use s::Timeout       , 10

  use s::DefaultSite   , 'http://api.mixi-platform.com/'
  use s::DefaultHeaders, {'Accept' => 'application/json'}

  use s::Oauth2Header  , nil

  use s::CommonLogger  , nil
  use s::Cache         , nil, 3600 do
    use s::ErrorHandler  , lambda{ |env| p env }
    use s::ErrorDetectorHttp
    use s::JsonDecode    , true
  end

  use s::Defaults      , :data     => lambda{{}}
end

module RestCore::Mixi::Client
  include RestCore

  def access_token
    data['access_token'] if data.kind_of?(Hash)
  end

  def authorize_url queries={}
    url('https://mixi.jp/connect_authorize.pl',
        {:client_id     => consumer_key,
         :response_type => 'code',
         :scope         => 'r_profile'}.merge(queries))
  end

  def authorize! code, payload={}, opts={}
    pl = {:client_id     => consumer_key   ,
          :client_secret => consumer_secret,
          :redirect_uri  => redirect_uri   ,
          :grant_type    => 'authorization_code',
          :code          => code}.merge(payload)

    self.data = post('https://secure.mixi-platform.com/2/token', pl, {}, opts)
  end
end

RestCore::Mixi.send(:include, RestCore::Mixi::Client)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rest-core-0.4.0.pre.1 lib/rest-core/client/mixi.rb