Created
October 23, 2014 16:55
-
-
Save sebastiangeiger/209d23a7508472204ea5 to your computer and use it in GitHub Desktop.
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 'faraday' | |
require 'json' | |
require 'pry' | |
require 'pp' | |
require 'rspec' | |
module Fulcrum | |
module Model; end | |
module API; end | |
end | |
class Fulcrum::Model::Form < Struct.new(:status) | |
end | |
class Fulcrum::API::FormParser | |
def initialize(request) | |
@json = JSON.parse(request.body) | |
end | |
def model | |
raise unless @json["form"] | |
@json["form"] | |
end | |
end | |
FULCRUM_API_CONNECTION = Faraday.new(url: 'https://api.fulcrumapp.com') do |faraday| | |
faraday.request :url_encoded # form-encode POST params | |
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP | |
faraday.headers["X-ApiToken"] = "20fc6a72253fb6e1372d77c4c2864c3bbd5eb3084167af176647e2d343750af2" | |
end | |
RSpec.describe "Retrieving and parsing a form" do | |
let(:response) do | |
FULCRUM_API_CONNECTION.get '/api/v2/forms/e20426c2-453d-4f5d-bc2f-103b46328898' | |
end | |
subject(:form) do | |
Fulcrum::API::FormParser.new(response).model | |
end | |
it { is_expected.to_not be_nil } | |
it 'prints' do | |
pp form | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment