This file contains hidden or 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
| # spec/spec_helper.rb | |
| RSpec.configure do |config| | |
| config.before(:each) do | |
| stub_request(:any, /supercool.com/).to_rack(FakeSuperCool) | |
| end | |
| end |
This file contains hidden or 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 'sinatra/base' | |
| class FakeSuperCool < Sinatra::Base | |
| get "/api/" do | |
| if params[:keywords] == 'ruby' | |
| json_response 200, 'super_cool_ruby_response.json' | |
| elsif params[:keywords] == 'rubular' | |
| json_response 200, 'super_cool_no_results_response.json' | |
| elsif params[:api_key] == '123' | |
| json_response 200, 'super_cool_bad_api_key_response.json' |
This file contains hidden or 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 TwitterService | |
| attr_reader :connection, :user | |
| def initialize(user) | |
| @user = user | |
| @connection = Faraday.new(url: "https://api.twitter.com/") | |
| end | |
| def friends | |
| response = connection.get do |req| |
This file contains hidden or 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 Friend | |
| def self.service(current_user) | |
| TwitterService.new(current_user) | |
| end | |
| def self.get_friends(current_user) | |
| friends_json = service(current_user).friends | |
| friends = friends_json.map do |friend| | |
| build_object(friend) | |
| end |
OlderNewer