Skip to content

Instantly share code, notes, and snippets.

@smtalim
Created September 20, 2011 05:01
Show Gist options
  • Save smtalim/1228369 to your computer and use it in GitHub Desktop.
Save smtalim/1228369 to your computer and use it in GitHub Desktop.

Revisions

  1. smtalim revised this gist Sep 20, 2011. 1 changed file with 31 additions and 0 deletions.
    31 changes: 31 additions & 0 deletions show.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    <div>
    <h1>A Sinatra app to access Google+</h1>
    <h3>Get Google+ Info</h3>

    <p>This Google+ ID belongs to <%= @gplus.row0 %></p>
    <p>
    <table id="hor-minimalist-a" summary="Google+ details">
    <thead>
    <tr>
    <th scope="col">Property</th>
    <th scope="col">Value</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>Tagline</td>
    <td><%= @gplus.row1 %></td>
    </tr>
    <tr>
    <td>G+ URL</td>
    <td><%= @gplus.row2 %></td>
    </tr>
    </tbody>
    </table>
    </p>

    <p><a href="/">Back</a></p>
    </div>
    <div id="footer">
    <p><b>A Fun Sinatra App for Google+ by RubyLearning 20 Sept. 2011</b>.</p>
    </div>
  2. smtalim revised this gist Sep 20, 2011. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions 500.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <div>
    <h1>A Sinatra app to access Google+</h1>
    <!--
    By default error will catch Sinatra::ServerError
    Sinatra will pass you the error via the ‘sinatra.error’
    in request.env
    -->
    <p>
    <% e = request.env['sinatra_error'] %>
    <%= p e.to_s %>
    <%= p e.backtrace.join("\n") %>
    Application error
    </p>
    </div>
    <div id="footer">
    <p><b>A Fun Sinatra App for Google+ by RubyLearning 20 Sept. 2011</b>.</p>
    </div>
  3. smtalim revised this gist Sep 20, 2011. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions 404.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    <div>
    <h1>A Sinatra app to access Google+</h1>
    <p>I'm sorry but the "The Sinatra app to access Google+" Web Service is not accessible from the folder you typed in.</p>
    <p>The correct URL is: <a href="http://sinatragplus.heroku.com/">http://sinatragplus.heroku.com/</a></p>
    <p><a href="/">Back</a></p>
    </div>
    <div id="footer">
    <p><b>A Fun Sinatra App for Google+ by RubyLearning 20 Sept. 2011</b>.</p>
    </div>
  4. smtalim revised this gist Sep 20, 2011. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions sinatragplus.rb
    Original file line number Diff line number Diff line change
    @@ -11,9 +11,7 @@ class GPlus
    def initialize(apikey, gid)
    @apikey = apikey
    @gid = gid
    puts "Calling get_info"
    get_info
    puts "Called get_info"
    end
    attr_reader :row0, :row1, :row2
    private
  5. smtalim revised this gist Sep 20, 2011. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions sinatragplus.rb
    Original file line number Diff line number Diff line change
    @@ -15,11 +15,10 @@ def initialize(apikey, gid)
    get_info
    puts "Called get_info"
    end
    attr_reader :row0, :row1, :row2, :row3, :row4, :row5, :row6, :row7
    attr_reader :row0, :row1, :row2
    private
    #Get info about specific G+ ID
    def get_info
    # Get your Google API key from https://code.google.com/apis/console#access
    # GooglePlus.api_key = 'Your API Key'
    begin
    GooglePlus.api_key = @apikey
    @@ -38,7 +37,7 @@ def get_info
    erb :index
    end

    # Display stock details
    # Display Google+ details
    post '/show' do
    @gplus = GPlus.new(params[:apikey], params[:gid])
    erb :show
  6. smtalim revised this gist Sep 20, 2011. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions index.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <div>
    <h1>A Sinatra app to access Google+</h1>
    <h3>Get Google+ Info</h3>
    <p>We shall be using Google+ to pull the given ID's information.</p>

    <form action="/show" method="post" accept-charset="utf-8">
    Enter your Google API Key: <input type="text" name="apikey" /><br />
    Enter your Google+ ID:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="gid" />
    <input type="submit" value=".. fetch the G+ info!">
    </form>
    </div>
    <div id="footer">
    <p><b>A Fun Sinatra App for Google+ by RubyLearning 20 Sept. 2011</b>.</p>
    </div>
  7. smtalim revised this gist Sep 20, 2011. 1 changed file with 45 additions and 0 deletions.
    45 changes: 45 additions & 0 deletions sinatragplus.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    # sinatragplus.rb
    require 'sinatra'
    require 'google_plus'

    error do
    erb :'500'
    end

    #class
    class GPlus
    def initialize(apikey, gid)
    @apikey = apikey
    @gid = gid
    puts "Calling get_info"
    get_info
    puts "Called get_info"
    end
    attr_reader :row0, :row1, :row2, :row3, :row4, :row5, :row6, :row7
    private
    #Get info about specific G+ ID
    def get_info
    # Get your Google API key from https://code.google.com/apis/console#access
    # GooglePlus.api_key = 'Your API Key'
    begin
    GooglePlus.api_key = @apikey
    person = GooglePlus::Person.get(@gid.to_i)
    @row0 = person.display_name
    @row1 = person.tagline
    @row2 = person.url
    rescue Exception => msg
    # display the system generated error message
    puts msg
    end
    end
    end

    get '/' do
    erb :index
    end

    # Display stock details
    post '/show' do
    @gplus = GPlus.new(params[:apikey], params[:gid])
    erb :show
    end
  8. smtalim revised this gist Sep 20, 2011. 1 changed file with 51 additions and 0 deletions.
    51 changes: 51 additions & 0 deletions style.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    body
    {
    line-height: 1.6em;
    }

    h1 {
    color: #2A1959;
    border-bottom: 2px solid #2A1959;
    }

    h2 {
    color: #474B94;
    font-size: 1.2 em;
    }

    #footer {
    clear: both;
    border-top: 1px solid #2A1959;
    text-align: left;
    height: 50px;
    font-size: 70%;
    width: 100%;
    }

    #hor-minimalist-a
    {
    font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
    font-size: 12px;
    background: #fff;
    margin: 45px;
    width: 480px;
    border-collapse: collapse;
    text-align: left;
    }
    #hor-minimalist-a th
    {
    font-size: 14px;
    font-weight: normal;
    color: #039;
    padding: 10px 8px;
    border-bottom: 2px solid #6678b1;
    }
    #hor-minimalist-a td
    {
    color: #669;
    padding: 9px 8px 0px 8px;
    }
    #hor-minimalist-a tbody tr:hover td
    {
    color: #009;
    }
  9. smtalim created this gist Sep 20, 2011.
    14 changes: 14 additions & 0 deletions layout.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>A Sinatra app to access Google+</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="RubyLearning.org" />
    <meta name="keywords" content="rubylearning,ruby,ruby programming,ruby course,sinatra course" />
    <link rel="stylesheet" type="text/css" href="/stylesheets/style.css" />
    <link rel="icon" type="image/ico" href="/images/favicon.ico" />
    </head>
    <body>
    <%= yield %>
    </body>
    </html>