whereby-ruby 0.1.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9855721503efc20f105aef1039daec4e4bd78342097b385459c3f178a2c6d7f2
4
- data.tar.gz: 33584783c746b352b37bcff4338b144df7f7baf071f2590abbb3b6f00aa1a582
3
+ metadata.gz: 45795394cb6d7781f4a95b4dbfe1743936aa9a481ce705c087c655e1a1414d44
4
+ data.tar.gz: b398759018a9d83579e3cfd0c2d870e323bb5f202fc5d2ec8aa2f2de04025c14
5
5
  SHA512:
6
- metadata.gz: 4a7c178ca9a840a1142a69fabde7a64926a2487f4361a4986092a29dec6504190357fb7dfd11c39bbc742345bd554484664809184724d9f2c6f7cac88693102d
7
- data.tar.gz: 5d45a3122767abda0469278a2df275f459cf963b4f8c5c0f39319c7b99349d88e8163ecd3f1f5f8a7e3b915e9685902d7bef901613553a4be88cd7b1d499357a
6
+ metadata.gz: e2474e5b8ad6db3fd56aa3d3168f847ef2c11c6172bc29b7d2b073a4277283b0ea23b610e68f2f641a339e4b509b8742674cbcc259f15ba06e7119fbfcd6e5ee
7
+ data.tar.gz: 1e7624bb7ccc39f692ba712b7ae7f3a523d9e253c19715fdd39d0b94e178567629cdad96760ea7269ce3191eed1a5bec95afd5b375f4c317265df2cfcef1bfb0
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Whereby Ruby HTTP API Wrapper
2
2
 
3
- Just a simple Whereby HTTP API wrapper written for Ruby projects.
3
+ This gem is a very simple [Whereby](https://whereby.com) HTTP API wrapper written for Ruby/Rails projects, to easly create video meetings and conferences.
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,16 +20,18 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- If using Rails put the following into a initializer. If just Ruby, run this before trying to use the API.
23
+ If using Rails put the following into an initializer. If you use plain Ruby, run this code before trying to use the API.
24
24
 
25
25
  ```ruby
26
26
  require 'whereby'
27
27
  Whereby.configure do |config|
28
- config.api_key = 'YOUR_KEY_HERE'
28
+ config.api_key = "Your api key!"
29
29
  end
30
30
  ```
31
+ By default, this gem try to read the `WHEREBY_API_KEY` environment variable and use that as api key. The above statement is therefore equivalent to setting this environment variable.
31
32
 
32
- ### Instantiate an API object.
33
+
34
+ ### Instantiate an API object
33
35
 
34
36
  ```ruby
35
37
  api = Whereby::Api.new
@@ -42,6 +44,12 @@ api.meeting(id) # GET /v1/meetings/:id
42
44
  api.create_meeting(options) # POST /v1/meetings
43
45
  api.delete_meeting(id) # DELETE /v1/meetings/:id
44
46
  ```
47
+ Read more about the different endpoints and options at https://whereby.dev/http-api/
48
+
49
+ ### Example creating a meeting
50
+ ```ruby
51
+ api.create_meeting(room_name_prefix: '/example', room_mode: "normal", start_date: "2020-08-01T00:00:00Z", end_date: "2020-08-01T15:00:00Z", fields: ["hostRoomUrl"])
52
+ ```
45
53
 
46
54
  ## Contributing
47
55
 
@@ -6,7 +6,7 @@ require 'whereby/api'
6
6
 
7
7
  module Whereby
8
8
  class << self
9
- attr_accessor :configuration
9
+ attr_writer :configuration
10
10
  end
11
11
 
12
12
  def self.api_key
@@ -20,6 +20,23 @@ module Whereby
20
20
  def self.configure
21
21
  yield(configuration)
22
22
  end
23
+ end
23
24
 
25
+ class String
26
+ def whereby_underscore
27
+ gsub(/::/, '/')
28
+ .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
29
+ .gsub(/([a-z\d])([A-Z])/,'\1_\2')
30
+ .tr('-', '_')
31
+ .downcase
32
+ end
33
+
34
+ def whereby_camelize
35
+ split('_').collect(&:capitalize).join
36
+ end
24
37
 
38
+ def whereby_lower_camelize
39
+ res = whereby_camelize
40
+ res[0].downcase + res[1..-1]
41
+ end
25
42
  end
@@ -1,60 +1,60 @@
1
1
  require 'httparty'
2
+ require 'json'
3
+
2
4
  module Whereby
3
5
  class WherebyError < StandardError; end
4
6
 
5
7
  class Api
6
- API_VERSION = 'v1'
7
- BASE_URL = "https://api.whereby.dev/#{API_VERSION}"
8
+ API_VERSION = 'v1'.freeze
9
+ BASE_URL = "https://api.whereby.dev/#{API_VERSION}".freeze
8
10
 
9
11
  # GET /v1/meetings/:id
10
12
  def meeting(id)
11
- Meeting.new(whereby_request(:get, "meetings/#{id.to_s}"))
13
+ Meeting.new(whereby_request(:get, "meetings/#{id}"))
12
14
  end
13
15
 
14
16
  # POST /v1/meetings/
15
- def create_meeting(options={})
16
- Meeting.new(whereby_request(:post, "meetings", options))
17
+ def create_meeting(**options)
18
+ Meeting.new(whereby_request(:post, 'meetings', options))
17
19
  end
18
20
 
19
21
  # DELETE /v1/meetings/:id
20
22
  def delete_meeting(id)
21
- whereby_request(:delete, "meetings/#{id.to_s}")
23
+ whereby_request(:delete, "meetings/#{id}")
22
24
  end
23
25
 
24
26
  private
25
- def whereby_request(method, url, options={})
26
- url = "#{BASE_URL}/#{url}"
27
-
28
- # Convert hash keys into camel case
29
- options = Hash[options.map { |k,v| [k.to_s.camelize, v]}]
30
27
 
31
- http_attrs = {headers: headers}
32
- http_attrs.merge!(options)
33
-
34
- # TODO: Create case/when for special cases for options
35
-
36
- result = HTTParty.send(method, url, http_attrs)
28
+ def whereby_request(method, url, options = {})
29
+ url = "#{BASE_URL}/#{url}"
30
+ result = HTTParty.send(method, url, { headers: headers, body: body(options) })
37
31
 
38
32
  if [200, 201].include? result.code
39
- JSON.parse(result.body) # Create / Get
33
+ JSON.parse(result.body)
40
34
  elsif result.code == 204
41
- true # Delete
35
+ true
42
36
  else
43
37
  raise WherebyError.new error(result.code)
44
38
  end
45
39
  end
46
40
 
47
- def error(code)
48
- return "Access token is missing or invalid" if code == 401
49
- return "The requested resource doesn't exist" if code == 404
50
- "Major fuck-up."
41
+ def body(options)
42
+ Hash[options.map { |k, v| [k.to_s.whereby_lower_camelize, v] }].to_json
51
43
  end
52
44
 
53
45
  def headers
54
46
  {
55
- "Content-type" => "application/json",
56
- "Authorization" => "Bearer #{Whereby.api_key}"
47
+ 'Content-type' => 'application/json',
48
+ 'Authorization' => "Bearer #{Whereby.api_key}"
57
49
  }
58
50
  end
51
+
52
+ def error(code)
53
+ return 'Access token is missing or invalid' if code == 401
54
+ return 'The requested resource does not exist' if code == 404
55
+
56
+ "The API resulted in an unknown status code: #{code}"
57
+ end
58
+
59
59
  end
60
60
  end
@@ -3,7 +3,7 @@ module Whereby
3
3
  attr_accessor :api_key
4
4
 
5
5
  def initialize
6
- @api_key = nil
6
+ @api_key = ENV["WHEREBY_API_KEY"]
7
7
  end
8
8
  end
9
9
  end
@@ -2,7 +2,7 @@ module Whereby
2
2
  class Element
3
3
  def initialize(attrs = {})
4
4
  # Only set attributes if the method exists
5
- attrs.each{ |k,v| send("#{k.underscore}=", v) if respond_to?("#{k.underscore}") }
5
+ attrs.each{ |k,v| send("#{k.whereby_underscore}=", v) if respond_to?(k.whereby_underscore.to_s) }
6
6
  end
7
7
 
8
8
  def to_h
@@ -1,3 +1,3 @@
1
1
  module Whereby
2
- VERSION = "0.1.4"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["tech@poption.com"]
11
11
 
12
12
  spec.summary = "A Ruby Whereby Wrapper"
13
- spec.description = "Easily use Whereby's HTTP API using this gem"
13
+ spec.description = "Easily use Whereby's HTTP API to create video rooms and conferences"
14
14
  spec.homepage = "https://github.com/poption/whereby-ruby"
15
15
  spec.license = "MIT"
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whereby-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Kittilsen Henriksen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-27 00:00:00.000000000 Z
11
+ date: 2020-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.18'
27
- description: Easily use Whereby's HTTP API using this gem
27
+ description: Easily use Whereby's HTTP API to create video rooms and conferences
28
28
  email:
29
29
  - tech@poption.com
30
30
  executables: []
@@ -54,7 +54,7 @@ metadata:
54
54
  homepage_uri: https://github.com/poption/whereby-ruby
55
55
  source_code_uri: https://github.com/poption/whereby-ruby
56
56
  changelog_uri: https://github.com/poption/whereby-ruby
57
- post_install_message:
57
+ post_install_message:
58
58
  rdoc_options: []
59
59
  require_paths:
60
60
  - lib
@@ -69,8 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 3.0.3
73
- signing_key:
72
+ rubygems_version: 3.0.8
73
+ signing_key:
74
74
  specification_version: 4
75
75
  summary: A Ruby Whereby Wrapper
76
76
  test_files: []