Module: Sinatra::TwitterServer

Defined in:
lib/twitter_server.rb

Defined Under Namespace

Modules: Helpers

Constant Summary collapse

HELP_XML_RESPONSE =
'<ok>true</ok>'.freeze
HELP_RESPONSE =
'ok'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



56
57
58
# File 'lib/twitter_server.rb', line 56

def self.registered(app)
  app.helpers Sinatra::TwitterServer::Helpers
end

Instance Method Details

#twitter_account_verify_credentialsObject



124
125
126
127
128
129
130
131
# File 'lib/twitter_server.rb', line 124

def 
  get "/account/verify_credentials.:format" do
    format  = params[:format]
    options = api_options
    user    = yield options
    render_xml_user(user)
  end
end

#twitter_basic_authObject



60
61
62
63
64
65
66
67
# File 'lib/twitter_server.rb', line 60

def twitter_basic_auth
  before do
    if base64 = env['HTTP_AUTHORIZATION']
      user, pass = Base64.decode64(base64.gsub(/Basic /, '')).split(":")
      @auth = yield user, pass
    end
  end
end

#twitter_helpObject



136
137
138
139
140
# File 'lib/twitter_server.rb', line 136

def twitter_help
  get "/help/test.:format" do
    params[:format] == 'xml' ? HELP_XML_RESPONSE : HELP_RESPONSE
  end
end

#twitter_statuses_friends_timelineObject



80
81
82
83
84
85
86
87
# File 'lib/twitter_server.rb', line 80

def twitter_statuses_friends_timeline
  get "/statuses/friends_timeline.:format" do
    options  = api_options(:since_id, :max_id, :count, :page)
    format   = params[:format]
    statuses = yield options
    render_xml_statuses(statuses)
  end
end

#twitter_statuses_home_timelineObject



70
71
72
73
74
75
76
77
# File 'lib/twitter_server.rb', line 70

def twitter_statuses_home_timeline
  get "/statuses/home_timeline.:format" do
    options  = api_options(:since_id, :max_id, :count, :page)
    format   = params[:format]
    statuses = yield options
    render_xml_statuses(statuses)
  end
end

#twitter_statuses_user_timelineObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/twitter_server.rb', line 90

def twitter_statuses_user_timeline
  get "/statuses/user_timeline.:format" do
    options  = api_options(:user_id, :screen_name, :since_id, :max_id, :count, :page)
    format   = params[:format]
    statuses = yield options
    render_xml_statuses(statuses)
  end

  get "/statuses/user_timeline/:id.:format" do
    options  = api_options(:id, :user_id, :screen_name, :since_id, :max_id, :count, :page)
    format   = params[:format]
    statuses = yield options
    render_xml_statuses(statuses)
  end
end

#twitter_users_showObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/twitter_server.rb', line 107

def twitter_users_show
  get "/users/show.:format" do
    options = api_options(:user_id, :screen_name)
    format  = params[:format]
    user    = yield options
    render_xml_user(user)
  end

  get "/users/show/:id.:format" do
    options = api_options(:id)
    format  = params[:format]
    user    = yield options
    render_xml_user(user)
  end
end