Skip to content

Commit

Permalink
Implement Services.getService
Browse files Browse the repository at this point in the history
  • Loading branch information
jacegu committed Apr 15, 2016
1 parent fad80dd commit 9338b10
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/dnsimple/client/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def all_services(options = {})
end
alias all all_services

def service(service_id, options = {})
endpoint = Client.versioned("/services/%s" % [service_id])
response = client.get(endpoint, options)

Dnsimple::Response.new(response, Struct::Service.new(response["data"]))
end
end
end
end
32 changes: 32 additions & 0 deletions spec/dnsimple/client/services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,36 @@
end
end

describe "#service" do
let(:service_id) { 1 }

before do
stub_request(:get, %r{/v2/services/#{service_id}$}).
to_return(read_http_fixture("getService/success.http"))
end

it "builds the correct request" do
subject.service(service_id)

expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/services/#{service_id}").
with(headers: { "Accept" => "application/json" })
end

it "returns the service" do
response = subject.service(service_id)
expect(response).to be_a(Dnsimple::Response)

service = response.data
expect(service).to be_a(Dnsimple::Struct::Service)
expect(service.id).to eq(1)
expect(service.name).to eq("Service 1")
expect(service.short_name).to eq("service1")
expect(service.description).to eq("First service example.")
expect(service.setup_description).to be_nil
expect(service.requires_setup).to be_falsey
expect(service.default_subdomain).to be_nil
expect(service.settings).to eq([])
end
end

end

0 comments on commit 9338b10

Please sign in to comment.