This repository was archived by the owner on Aug 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Integrate twitter #21 #52
Open
Joerg-Seitz
wants to merge
2
commits into
master
Choose a base branch
from
integrate-twitter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| class Api::OceansController < ApplicationController | ||
| protect_from_forgery with: :null_session | ||
| before_filter :render_bad_request, unless: :limit_valid? | ||
|
|
||
| def index | ||
| oceans = Array.new(number_of_oceans) do | ||
| OceanService.new(Random.rand(1..5)).call | ||
| end | ||
| render json: oceans | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def number_of_oceans | ||
| @number_of_oceans ||= params.fetch(:limit, 4).to_i | ||
| end | ||
|
|
||
| def render_bad_request | ||
| render nothing: true, status: :bad_request | ||
| end | ||
|
|
||
| def limit_valid? | ||
| number_of_oceans.between?(0, 20) | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| class TwitterService | ||
| APP_CONFIG = YAML.load(File.read('config/settings/development.yml')) | ||
| .with_indifferent_access | ||
|
|
||
| def initialize | ||
| @client = Twitter::REST::Client.new do |config| | ||
| config.consumer_key = APP_CONFIG['consumer_key'] | ||
| config.consumer_secret = APP_CONFIG['consumer_secret'] | ||
| config.access_token = APP_CONFIG['access_token'] | ||
| config.access_token_secret = APP_CONFIG['access_token_secret'] | ||
| end | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| Config.setup do |config| | ||
| # Name of the constant exposing loaded settings | ||
| config.const_name = 'Settings' | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i guess here you define the const... so you should be able to do something like
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also I don't think we need this anymore, since rails ships with a secrets store (the one I linked in the issue) |
||
|
|
||
| # Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'. | ||
| # | ||
| # config.knockout_prefix = nil | ||
|
|
||
| # Overwrite arrays found in previously loaded settings file. When set to `false`, arrays will be merged. | ||
| # | ||
| # config.overwrite_arrays = true | ||
|
|
||
| # Load environment variables from the `ENV` object and override any settings defined in files. | ||
| # | ||
| # config.use_env = false | ||
|
|
||
| # Define ENV variable prefix deciding which variables to load into config. | ||
| # | ||
| # config.env_prefix = 'Settings' | ||
|
|
||
| # What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well | ||
| # with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where | ||
| # using dots in variable names might not be allowed (eg. Bash). | ||
| # | ||
| # config.env_separator = '.' | ||
|
|
||
| # Ability to process variables names: | ||
| # * nil - no change | ||
| # * :downcase - convert to lower case | ||
| # | ||
| # config.env_converter = :downcase | ||
|
|
||
| # Parse numeric values as integers instead of strings. | ||
| # | ||
| # config.env_parse_values = true | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| Rails.application.routes.draw do | ||
| resources :islands, only: :index | ||
| root 'islands#index' | ||
| resources :islands, only: :index | ||
| resources :test_oceans, only: :index | ||
| namespace :api, defaults: { format: 'json' } do | ||
| resources :oceans, only: :index | ||
| end | ||
| end |
Empty file.
Empty file.
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Api::OceansController do | ||
| let(:json_response) { JSON.parse(response.body) } | ||
| let(:oceans) { json_response } | ||
| let(:ocean_service) { instance_double(OceanService, call: 'ocean') } | ||
|
|
||
| it 'renders 4 oceans, when there are no additional parameters' do | ||
| get :index | ||
| expect(response).to be_success | ||
| expect(oceans.size).to be 4 | ||
| end | ||
|
|
||
| it 'renders 0 oceans' do | ||
| get :index, limit: '0' | ||
| expect(response).to be_success | ||
| expect(oceans.size).to be | ||
| end | ||
|
|
||
| it 'calls the OceanService with 4 as limit' do | ||
| expect(OceanService) | ||
| .to(receive(:new).exactly(4).times.and_return(ocean_service)) | ||
| get :index, limit: '4' | ||
| expect(oceans).to eq %w(ocean ocean ocean ocean) | ||
| end | ||
|
|
||
| it 'calls the ocean with forbidden parameters (< 0 | > 20)' do | ||
| get :index, limit: '21' | ||
| expect(response).to be_bad_request | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess you are using this wrong.... the point of using a settings gem is not to load it manually. And especially have it load the right constant for the right environment. Here you hardcode development.yml