Class: Joinme2::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/joinme2/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/joinme2/client.rb', line 16

def initialize(options = {})
  oauth_token = options[:oauth_token]

  options = Joinme2.options.merge(options)
  [:base_uri, :default_scopes, :redirect_uri, :client_id, :auth_uri].each do |accessor|
    send("#{accessor}=", options[accessor])
  end

  self.class.base_uri base_uri
  @options = {
    headers: {
      "Authorization" => "Bearer #{oauth_token}",
      "Content-Type" => "application/json",
      "User-Agent" => 'X-JOINME-CLIENT'
    }
  }
end

Instance Attribute Details

#auth_uriObject

Returns the value of attribute auth_uri.



6
7
8
# File 'lib/joinme2/client.rb', line 6

def auth_uri
  @auth_uri
end

#base_uriObject

Returns the value of attribute base_uri.



6
7
8
# File 'lib/joinme2/client.rb', line 6

def base_uri
  @base_uri
end

#client_idObject

Returns the value of attribute client_id.



6
7
8
# File 'lib/joinme2/client.rb', line 6

def client_id
  @client_id
end

#default_scopesObject

Returns the value of attribute default_scopes.



6
7
8
# File 'lib/joinme2/client.rb', line 6

def default_scopes
  @default_scopes
end

#redirect_uriObject

Returns the value of attribute redirect_uri.



6
7
8
# File 'lib/joinme2/client.rb', line 6

def redirect_uri
  @redirect_uri
end

Instance Method Details

#authorize_url(options = {}) ⇒ Object

Public: Generates Joinme authorization url based on client_id, auth_uri redirect_uri and scopes. Redirect URI has to match configured Joinme Application callback URL.

Examples:

authorize_url(redirect_uri: 'http://example.com/',
              scope: "user_info scheduler start_meeting",
              client_id: "XXXXX")
# =>
"https://secure.join.me/api/public/v1/auth/oauth2..."

Returns authorization url as a string.



47
48
49
50
51
52
53
54
55
# File 'lib/joinme2/client.rb', line 47

def authorize_url(options = {})
  params = {}
  params[:scope] = options[:scope] || default_scopes
  params[:redirect_uri] = options[:redirect_uri] || redirect_uri
  params[:client_id] = options[:client_id] || client_id
  URI.parse(auth_uri).tap do |uri|
    uri.query = URI.encode_www_form params
  end.to_s
end

#delete_meeting(id) ⇒ Object



103
104
105
# File 'lib/joinme2/client.rb', line 103

def delete_meeting(id)
  self.class.delete("/meetings/#{id}", @options)
end

#get_scheduled_meeting(id) ⇒ Object



70
71
72
# File 'lib/joinme2/client.rb', line 70

def get_scheduled_meeting(id)
  self.class.get("/meetings/#{id}", @options)
end

#get_scheduled_meetings(end_date = nil) ⇒ Object



74
75
76
77
78
# File 'lib/joinme2/client.rb', line 74

def get_scheduled_meetings(end_date = nil)
  payload = @options.dup
  payload[:headers][:endDate] = end_date if end_date
  self.class.get('/meetings', @options)
end

#get_userObject



107
108
109
# File 'lib/joinme2/client.rb', line 107

def get_user
  self.class.get('/user', @options)
end

#schedule_new_meeting(name, participants = [], start_date, end_date) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/joinme2/client.rb', line 80

def schedule_new_meeting(name, participants = [], start_date, end_date)
  body = {}
  body[:startWithPersonalUrl] = false
  body[:meetingStart] = iso_date!(start_date)
  body[:meetingEnd] = iso_date!(end_date)
  body[:meetingName] = name
  body[:participants] = participants
  payload = @options.dup
  payload[:body] = body.to_json
  self.class.post('/meetings', payload)
end

#start_new_meeting(body = { "startWithPersonalUrl": false }) ⇒ Object

Public: Connects to Joinme API and starts new meeting.

Returns Hashie::Mash representation of API response.



60
61
62
63
64
# File 'lib/joinme2/client.rb', line 60

def start_new_meeting(body = { "startWithPersonalUrl": false })
  payload = @options.dup
  payload[:body] = body.to_json
  self.class.post('/meetings/start', payload)
end

#start_sheduled_meeting(id) ⇒ Object



66
67
68
# File 'lib/joinme2/client.rb', line 66

def start_sheduled_meeting(id)
  self.class.post("/meetings/#{id}/start", @options)
end

#update_meeting(id, name = nil, participant = nil, start_date = nil, end_date = nil) ⇒ Object



92
93
94
95
96
97
98
99
100
101
# File 'lib/joinme2/client.rb', line 92

def update_meeting(id, name = nil, participant = nil, start_date = nil, end_date = nil)
  body = {}
  body[:meetingStart] = iso_date(start_date)
  body[:meetingEnd] = iso_date(end_datee)
  body[:meetingName] = name
  body[:participants] = participants
  payload = @options.dup
  payload[:body] = body.to_json
  self.class.patch("/meetings/#{id}", payload)
end