Class: OrbitMembers::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/orbit_members/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Request

Returns a new instance of Request.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/orbit_members/request.rb', line 9

def initialize(params = {})
  @action = params.fetch(:action)
  @api_key = params.fetch(:api_key)
  @workspace_id = params.fetch(:workspace_id)
  @user_agent = params.fetch(:user_agent, "ruby-orbit-members/#{OrbitMembers::VERSION}")
  @body = params.fetch(:body, nil)
  @filters = params.fetch(:filters, nil)
  @member_id = params.fetch(:member_id, nil)
  @activity_id = params.fetch(:activity_id, nil)

  after_initialize!
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



7
8
9
# File 'lib/orbit_members/request.rb', line 7

def action
  @action
end

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/orbit_members/request.rb', line 7

def api_key
  @api_key
end

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/orbit_members/request.rb', line 7

def body
  @body
end

#filtersObject (readonly)

Returns the value of attribute filters.



7
8
9
# File 'lib/orbit_members/request.rb', line 7

def filters
  @filters
end

#member_idObject (readonly)

Returns the value of attribute member_id.



7
8
9
# File 'lib/orbit_members/request.rb', line 7

def member_id
  @member_id
end

#user_agentObject (readonly)

Returns the value of attribute user_agent.



7
8
9
# File 'lib/orbit_members/request.rb', line 7

def user_agent
  @user_agent
end

#workspace_idObject (readonly)

Returns the value of attribute workspace_id.



7
8
9
# File 'lib/orbit_members/request.rb', line 7

def workspace_id
  @workspace_id
end

Instance Method Details

#add_identityObject



72
73
74
75
76
77
78
79
# File 'lib/orbit_members/request.rb', line 72

def add_identity
  OrbitMembers::HTTP.post(
    url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}/identities",
    user_agent: @user_agent,
    api_key: @api_key,
    body: @body
  )
end

#after_initialize!Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/orbit_members/request.rb', line 22

def after_initialize!
  case @action
  when "create_member"
    create_member
  when "get_member"
    get_member
  when "list_members"
    list_members
  when "add_identity"
    add_identity
  when "remove_identity"
    remove_identity
  when "update_member"
    update_member
  when "delete_member"
    delete_member
  when "find_member_by_identity"
    find_member_by_identity
  else
    raise ArgumentError,
          "Activity type is unrecognized. Must be one of: create_member, update_member, get_member, list_members, add_identity, remove_identity, update_member, delete_member, find_member_by_identity"
  end
end

#create_memberObject



46
47
48
49
50
51
52
53
# File 'lib/orbit_members/request.rb', line 46

def create_member
  OrbitMembers::HTTP.post(
    url: "https://app.orbit.love/api/v1/#{@workspace_id}/members",
    user_agent: @user_agent,
    api_key: @api_key,
    body: @body
  )
end

#delete_memberObject



99
100
101
102
103
104
105
# File 'lib/orbit_members/request.rb', line 99

def delete_member
  OrbitMembers::HTTP.delete(
    url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}",
    user_agent: @user_agent,
    api_key: @api_key
  )
end

#find_member_by_identityObject



107
108
109
110
111
112
113
114
# File 'lib/orbit_members/request.rb', line 107

def find_member_by_identity
  OrbitMembers::HTTP.get(
    url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/find",
    user_agent: @user_agent,
    api_key: @api_key,
    filters: @filters
  )
end

#get_memberObject



55
56
57
58
59
60
61
# File 'lib/orbit_members/request.rb', line 55

def get_member
  OrbitMembers::HTTP.get(
    url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}",
    user_agent: @user_agent,
    api_key: @api_key
  )
end

#list_membersObject



63
64
65
66
67
68
69
70
# File 'lib/orbit_members/request.rb', line 63

def list_members
  OrbitMembers::HTTP.get(
    url: "https://app.orbit.love/api/v1/#{@workspace_id}/members",
    user_agent: @user_agent,
    api_key: @api_key,
    filters: @filters
  )
end

#remove_identityObject



81
82
83
84
85
86
87
88
# File 'lib/orbit_members/request.rb', line 81

def remove_identity
  OrbitMembers::HTTP.delete(
    url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}/identities",
    user_agent: @user_agent,
    api_key: @api_key,
    body: @body
  )
end

#update_memberObject



90
91
92
93
94
95
96
97
# File 'lib/orbit_members/request.rb', line 90

def update_member
  OrbitMembers::HTTP.put(
    url: "https://app.orbit.love/api/v1/#{@workspace_id}/members/#{@member_id}",
    user_agent: @user_agent,
    api_key: @api_key,
    body: @body
  )
end