Class: Sentry::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, slug) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/sentry/client.rb', line 7

def initialize(token, slug)
  self.token = token
  self.slug = slug
  self.base_url = "https://sentry.io/api/0/projects/"
end

Instance Attribute Details

#base_urlObject

Returns the value of attribute base_url.



5
6
7
# File 'lib/sentry/client.rb', line 5

def base_url
  @base_url
end

#prefixObject

Returns the value of attribute prefix.



5
6
7
# File 'lib/sentry/client.rb', line 5

def prefix
  @prefix
end

#slugObject

Returns the value of attribute slug.



5
6
7
# File 'lib/sentry/client.rb', line 5

def slug
  @slug
end

#tokenObject

Returns the value of attribute token.



5
6
7
# File 'lib/sentry/client.rb', line 5

def token
  @token
end

Instance Method Details

#create_release(version) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sentry/client.rb', line 13

def create_release(version)
  response = Typhoeus.get(
    "#{base_url}/#{slug}/releases/#{version}/",
    headers: {
      "Authorization" => "Bearer #{token}",
      "Content-Type" =>  "application/json"
    }
  )
  if response.response_code == 200
    # Release already present, skipping...
    return response
  end

  Typhoeus.post(
    "#{base_url}/#{slug}/releases/",
    headers: {
      "Authorization" => "Bearer #{token}",
      "Content-Type" =>  "application/json"
    },
    body: JSON.dump({ version: version })
  )
end

#upload_release_artifact(version, artifact_path, filename_prefix = "") ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/sentry/client.rb', line 36

def upload_release_artifact(version, artifact_path, filename_prefix = "")
  Typhoeus.post(
    "#{base_url}/#{slug}/releases/#{version}/files/",
    headers: { "Authorization" => "Bearer #{token}" },
    body: {
      file: File.open(artifact_path, "r"),
      name: "#{filename_prefix}#{File.basename(artifact_path)}"
    }
  )
end