Class: SeismicAPI::TeamsitesStub

Inherits:
Object
  • Object
show all
Includes:
WebMock::API
Defined in:
lib/seismic_api/teamsites_stub.rb

Instance Method Summary collapse

Instance Method Details

#add_folder(**args) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/seismic_api/teamsites_stub.rb', line 7

def add_folder(**args)
  authorization = args.fetch(:authorization, /Bearer [\w.-]+$/)
  teamsite_id = args.fetch(:teamsite_id, "1")
  new_folder_id = args.fetch(:new_folder_id, "1234arst")
  name = args.fetch(:name, "New Folder")
  parent_folder_id = args.fetch(:parent_folder_id, "root")
  options = args.fetch(:options, {})

  post_body = {
    name: name,
    parentFolderId: parent_folder_id
  }.merge(options)
  response_body = {
    id: new_folder_id,
    name: name,
    parentFolderId: parent_folder_id
  }.merge(options).to_json

  stub_request(:post, "#{teamsites_url}/#{teamsite_id}/folders")
    .with(
      headers: { "Authorization" => authorization },
      body: post_body
  ).to_return(body: response_body)
end

#add_url(**args) ⇒ Object


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/seismic_api/teamsites_stub.rb', line 86

def add_url(**args)
  teamsite_id = args.fetch(:teamsite_id, "1")
  authorization = args.fetch(:authorization, /Bearer [\w.-]+$/)
  new_url_id = args.fetch(:new_url_id, "32")
  post_body = args.fetch(:post_body)
  return_body = post_body.reject { |k,v| %i(:parentFolderId).include?(k) }

  stub_request(:post, "#{teamsites_url}/#{teamsite_id}/urls")
    .with(
      headers: { "Authorization" => authorization },
      body: post_body
  ).to_return(body: {
    id: new_url_id,
    **return_body
  }.to_json)
end

#add_url_duplicate_name(**args) ⇒ Object


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/seismic_api/teamsites_stub.rb', line 103

def add_url_duplicate_name(**args)
  teamsite_id = args.fetch(:teamsite_id, "1")
  authorization = args.fetch(:authorization, /Bearer [\w.-]+$/)
  post_body = args.fetch(:post_body)

  stub_request(:post, "#{teamsites_url}/#{teamsite_id}/urls")
    .with(
      headers: { "Authorization" => authorization },
      body: post_body
  )
    .to_return(
      status: 400,
      body: {
        error: {
          message: "A url with name '#{post_body[:name]}' already exists in the target folder."
        }
      }.to_json
  )
end

#all(**args) ⇒ Object


32
33
34
35
36
37
38
39
40
41
# File 'lib/seismic_api/teamsites_stub.rb', line 32

def all(**args)
  authorization = args.fetch(:authorization, /Bearer [\w.-]+$/)
  teamsites = args.fetch(:teamsites) do
    [{ "id" => 4, "name" => "SomeTeamsite" }]
  end

  stub_request(:get, teamsites_url)
    .with(headers: { "Authorization" => authorization })
    .to_return(body: teamsites.to_json)
end

#base_urlObject


207
208
209
# File 'lib/seismic_api/teamsites_stub.rb', line 207

def base_url
  "https://api.seismic.com/integration/v2"
end

#find(**args) ⇒ Object


43
44
45
46
47
48
49
50
51
# File 'lib/seismic_api/teamsites_stub.rb', line 43

def find(**args)
  teamsite_id = args.fetch(:teamsite_id, "1")
  name = args.fetch(:name, "Teamsite Name")
  authorization = args.fetch(:authorization, /Bearer [\w.-]+$/)

  stub_request(:get, "#{teamsites_url}/#{teamsite_id}")
    .with(headers: { 'Authorization' => authorization })
    .to_return(body: { "id" => teamsite_id, "name" => name }.to_json)
end

#items(**args) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/seismic_api/teamsites_stub.rb', line 53

def items(**args)
  teamsite_id = args.fetch(:teamsite_id, "1")
  item_count = args.fetch(:item_count, 1)
  items = args.fetch(:items) do
    [
      {
        id: "1234arst",
        url: { url: "www.lessonly.com", openInNewWindow: false },
        size: 1234,
        version: "versionnumber"
      }
    ]
  end
  external_id = args[:external_id]
  ext_connection_id = args[:external_connection_id]
  query = {}
  query[:externalId] = external_id if external_id
  query[:externalConnectionId] = ext_connection_id if ext_connection_id
  authorization = args.fetch(:authorization, /Bearer [\w.-]+$/)

  return_body = {
    itemCount: Integer(item_count),
    items: items
  }.to_json

  stub_request(:get, "#{teamsites_url}/#{teamsite_id}/items")
    .with(
      headers: { "Authorization" => authorization },
      query: query
  )
    .to_return(body: return_body)
end

#publish_with_warning(**args) ⇒ Object


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/seismic_api/teamsites_stub.rb', line 123

def publish_with_warning(**args)
  teamsite_id = args.fetch(:teamsite_id, "1")
  content_id = args.fetch(:content_id, "1234arst")
  authorization = args.fetch(:authorization, /Bearer [\w.-]+$/)
  return_body = args.fetch(return_body) do
    {
      "totalRequests" => "1",
      "totalErrors" => "0",
      "totalSucceeded" => "1",
      "totalWarnings" => "0",
      "errors" => [],
      "warnings"=>[
        {
          "id"=>String(content_id),
          "message"=>"Content promoted, but could not be published."
        }
      ]
    }
  end

  stub_request(:post, "#{teamsites_url}/#{teamsite_id}/publish")
    .with(
      headers: { "Authorization" => authorization },
      body: {
        content: [
          { id: content_id }
        ]
      }
  ).to_return(body: return_body.to_json)
end

#teamsites_urlObject


211
212
213
# File 'lib/seismic_api/teamsites_stub.rb', line 211

def teamsites_url
  base_url + "/teamsites"
end

#unpublish(**args) ⇒ Object


154
155
156
157
158
159
160
161
162
163
164
# File 'lib/seismic_api/teamsites_stub.rb', line 154

def unpublish(**args)
  teamsite_id = args.fetch(:teamsite_id, "1")
  content_id = args.fetch(:content_id, "1234arst")
  authorization = args.fetch(:authorization, /Bearer [\w.-]+$/)

  stub_request(:put, "#{teamsites_url}/#{teamsite_id}/items/#{content_id}/unpublish")
    .with(
      headers: { "Authorization" => authorization }
  )
    .to_return(body: "")
end

#unpublish_when_not_published(**args) ⇒ Object


166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/seismic_api/teamsites_stub.rb', line 166

def unpublish_when_not_published(**args)
  teamsite_id = args.fetch(:teamsite_id, "1")
  content_id = args.fetch(:content_id, "1234arst")
  authorization = args.fetch(:authorization, /Bearer [\w.-]+$/)

  stub_request(:put, "#{teamsites_url}/#{teamsite_id}/items/#{content_id}/unpublish")
    .with(
      headers: { "Authorization" => authorization }
  )
    .to_return(
      status: 400,
      body: {
        error: {
          message: "Unpublished failed. Content #{content_id} is not published"
        }
      }.to_json
  )
end

#update_url(**args) ⇒ Object


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/seismic_api/teamsites_stub.rb', line 185

def update_url(**args)
  teamsite_id = args.fetch(:teamsite_id, "1")
  content_id = args.fetch(:content_id)
  authorization = args.fetch(:authorization, /Bearer [\w.-]+$/)
  post_body = args.fetch(:post_body)
  return_body = {
    id: "1234arst",
    name: "Some Content",
    url: { url: "www.lessonly.com", openInNewWindow: false },
    size: 1234,
    version: "1.0"
  }.merge(post_body)

  stub_request(:patch, "#{teamsites_url}/#{teamsite_id}/urls/#{content_id}")
    .with(
      headers: { "Authorization" => authorization },
      body: post_body
  ).to_return(body: {
    **return_body
  }.to_json)
end