-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from poption/release/v.1.0.0
Added string helper methods and request body is set to be formatted as json
- Loading branch information
Showing
7 changed files
with
58 additions
and
35 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,60 @@ | ||
require 'httparty' | ||
require 'json' | ||
|
||
module Whereby | ||
class WherebyError < StandardError; end | ||
|
||
class Api | ||
API_VERSION = 'v1' | ||
BASE_URL = "https://api.whereby.dev/#{API_VERSION}" | ||
API_VERSION = 'v1'.freeze | ||
BASE_URL = "https://api.whereby.dev/#{API_VERSION}".freeze | ||
|
||
# GET /v1/meetings/:id | ||
def meeting(id) | ||
Meeting.new(whereby_request(:get, "meetings/#{id.to_s}")) | ||
Meeting.new(whereby_request(:get, "meetings/#{id}")) | ||
end | ||
|
||
# POST /v1/meetings/ | ||
def create_meeting(options={}) | ||
Meeting.new(whereby_request(:post, "meetings", options)) | ||
def create_meeting(**options) | ||
Meeting.new(whereby_request(:post, 'meetings', options)) | ||
end | ||
|
||
# DELETE /v1/meetings/:id | ||
def delete_meeting(id) | ||
whereby_request(:delete, "meetings/#{id.to_s}") | ||
whereby_request(:delete, "meetings/#{id}") | ||
end | ||
|
||
private | ||
def whereby_request(method, url, options={}) | ||
url = "#{BASE_URL}/#{url}" | ||
|
||
# Convert hash keys into camel case | ||
options = Hash[options.map { |k,v| [k.to_s.camelize, v]}] | ||
|
||
http_attrs = {headers: headers} | ||
http_attrs.merge!(options) | ||
|
||
# TODO: Create case/when for special cases for options | ||
|
||
result = HTTParty.send(method, url, http_attrs) | ||
def whereby_request(method, url, options = {}) | ||
url = "#{BASE_URL}/#{url}" | ||
result = HTTParty.send(method, url, { headers: headers, body: body(options) }) | ||
|
||
if [200, 201].include? result.code | ||
JSON.parse(result.body) # Create / Get | ||
JSON.parse(result.body) | ||
elsif result.code == 204 | ||
true # Delete | ||
true | ||
else | ||
raise WherebyError.new error(result.code) | ||
end | ||
end | ||
|
||
def error(code) | ||
return "Access token is missing or invalid" if code == 401 | ||
return "The requested resource doesn't exist" if code == 404 | ||
"Major fuck-up." | ||
def body(options) | ||
Hash[options.map { |k, v| [k.to_s.whereby_lower_camelize, v] }].to_json | ||
end | ||
|
||
def headers | ||
{ | ||
"Content-type" => "application/json", | ||
"Authorization" => "Bearer #{Whereby.api_key}" | ||
'Content-type' => 'application/json', | ||
'Authorization' => "Bearer #{Whereby.api_key}" | ||
} | ||
end | ||
|
||
def error(code) | ||
return 'Access token is missing or invalid' if code == 401 | ||
return 'The requested resource does not exist' if code == 404 | ||
|
||
"The API resulted in an unknown status code: #{code}" | ||
end | ||
|
||
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Whereby | ||
VERSION = "0.1.4" | ||
VERSION = "1.0.0" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec| | |
spec.email = ["[email protected]"] | ||
|
||
spec.summary = "A Ruby Whereby Wrapper" | ||
spec.description = "Easily use Whereby's HTTP API using this gem" | ||
spec.description = "Easily use Whereby's HTTP API to create video rooms and conferences" | ||
spec.homepage = "https://github.com/poption/whereby-ruby" | ||
spec.license = "MIT" | ||
|
||
|