Class: GoogleContentApi::SubAccount

Inherits:
Object
  • Object
show all
Defined in:
lib/google_content_api/sub_account.rb

Class Method Summary collapse

Class Method Details

.create(title, adult_content = false, attributes = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/google_content_api/sub_account.rb', line 23

def create(title, adult_content = false, attributes = {})
  prepare_request_params(title, adult_content, attributes)
  response = Faraday.post @sub_accounts_url, @xml

  if response.status == 201
    response
  else
    raise "Unable to create sub account - received status #{response.status}. body: #{response.body}"
  end
end

.delete(google_id) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/google_content_api/sub_account.rb', line 45

def delete(google_id)
  token           = Authorization.fetch_token
   = GoogleContentApi.urls("managed_accounts", google_user_id)
  Faraday.headers = { "Authorization"  => "AuthSub token=#{token}" }
  response        = Faraday.delete "#{}/#{google_id}"

  if response.status == 200
    response
  else
    raise "Unable to delete sub account - received status #{response.status}. body: #{response.body}"
  end
end

.get_allObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/google_content_api/sub_account.rb', line 6

def get_all
  token            = Authorization.fetch_token
  sub_accounts_url = GoogleContentApi.urls("managed_accounts", google_user_id)
  Faraday.headers  = {
    "Content-Type"  => "application/atom+xml",
    "Authorization" => "AuthSub token=#{token}"
  }

  response = Faraday.get sub_accounts_url

  if response.status == 200
    response
  else
    raise "request unsuccessful - received status #{response.status}"
  end
end

.update(title, google_id, adult_content = false, attributes = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/google_content_api/sub_account.rb', line 34

def update(title, google_id, adult_content = false, attributes = {})
  prepare_request_params(title, adult_content, attributes)
  response = Faraday.put "#{@sub_accounts_url}/#{google_id}", @xml

  if response.status == 200
    response
  else
    raise "Unable to update sub account - received status #{response.status}. body: #{response.body}"
  end
end