This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stub_request(:post, "https://api.twitter.com/oauth/request_token"). | |
to_return(:body => "oauth_token=t&oauth_token_secret=s") | |
stub_request(:post, "https://api.twitter.com/oauth/access_token"). | |
to_return(:body => "oauth_token=at&oauth_token_secret=as&screen_name=sn") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'oauth' | |
require 'launchy' | |
CONSUMER_KEY = 'your_consumer_key' | |
CONSUMER_SECRET = 'your_consumer_secret' | |
CALLBACK_URL = 'oob' | |
consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site => "https://api.twitter.com/") | |
request_token = consumer.get_request_token(:oauth_callback => CALLBACK_URL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEST_ACCOUNT_SID = 'whatever' | |
TEST_AUTH_TOKEN = 'ha' | |
require 'faraday' | |
require 'base64' | |
post_response = Faraday.post do |request| | |
request.url "https://api.twilio.com/2010-04-01/Accounts/#{TEST_ACCOUNT_SID}/SMS/Messages.json" | |
request.headers['Authorization'] = "Basic " + Base64.strict_encode64("#{TEST_ACCOUNT_SID}:#{TEST_AUTH_TOKEN}") | |
request.body = URI.encode_www_form({'From' => '+15005550006', 'To' => '+14155551212', 'Body' => 'hello world!'}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_model' | |
class Foo | |
include ActiveModel::Validations | |
attr_accessor :name | |
validates :name, :presence => true | |
def initialize(options={}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe Gist do | |
context '.create' do | |
it 'POSTs a new Gist to the user\'s account' do | |
gist = {:public => 'true', | |
:description => 'a test gist', | |
:files => {'test_file.rb' => {:content => 'puts "hello world!"'}}} | |
stub = stub_request(:post, "https://#{GITHUB_USERNAME}:#{GITHUB_PASSWORD}@api.github.com/gists").with(:body => gist.to_json) | |
Gist.create(gist) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def factorial(n) | |
if n < 0 | |
raise "You can't take the factorial of a negative number." | |
elsif n == 0 | |
1 | |
else | |
(1..n).inject(:*) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.michael.forecaster; | |
import com.squareup.okhttp.Call; | |
import com.squareup.okhttp.Callback; | |
import com.squareup.okhttp.OkHttpClient; | |
import com.squareup.okhttp.Request; | |
public class Forecaster { | |
public void fetchForecast(int zip, Callback callback) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Integer | |
def in_words | |
if self < 20 | |
{0 => "\b", | |
1 => "one", | |
2 => "two", | |
3 => "three", | |
4 => "four", | |
5 => "five", | |
6 => "six", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Integer | |
def in_words | |
if self < 20 | |
{0 => "\b", | |
1 => "one", | |
2 => "two", | |
3 => "three", | |
4 => "four", | |
5 => "five", | |
6 => "six", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Integer | |
def in_words | |
if self < 20 | |
{0 => "\b", | |
1 => "one", | |
2 => "two", | |
3 => "three", | |
4 => "four", | |
5 => "five", | |
6 => "six", |