Class: HeedKit::Client

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

Overview

Server-side client for the HeedKit API. Talks to the public roadmap endpoint and the end-user SDK endpoints (X-Project-Key auth).

Constant Summary collapse

DEFAULT_TIMEOUT =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_key:, endpoint:, timeout: DEFAULT_TIMEOUT) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
# File 'lib/heedkit/client.rb', line 15

def initialize(project_key:, endpoint:, timeout: DEFAULT_TIMEOUT)
  raise ArgumentError, "project_key is required" if project_key.to_s.empty?
  raise ArgumentError, "endpoint is required" if endpoint.to_s.empty?

  @project_key = project_key
  @endpoint = endpoint.to_s.chomp("/")
  @timeout = timeout
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



13
14
15
# File 'lib/heedkit/client.rb', line 13

def endpoint
  @endpoint
end

#project_keyObject (readonly)

Returns the value of attribute project_key.



13
14
15
# File 'lib/heedkit/client.rb', line 13

def project_key
  @project_key
end

Instance Method Details

#changelogObject

GET the public changelog. Returns a HeedKit::Changelog.



30
31
32
# File 'lib/heedkit/client.rb', line 30

def changelog
  Changelog.from_payload(get("/public/projects/#{project_key}/changelog"))
end

#comment(feature_id, end_user_id:, body:) ⇒ Object

POST /sdk/features/:id/comments — comment as an end-user.



57
58
59
# File 'lib/heedkit/client.rb', line 57

def comment(feature_id, end_user_id:, body:)
  sdk_post("/sdk/features/#{feature_id}/comments", end_user_id:, body:)
end

#features(end_user_id: nil, status: nil, kind: nil, sort: "top", cursor: nil) ⇒ Object

GET /sdk/features — public features plus the caller's own private submissions.



41
42
43
44
# File 'lib/heedkit/client.rb', line 41

def features(end_user_id: nil, status: nil, kind: nil, sort: "top", cursor: nil)
  query = { end_user_id:, status:, kind:, sort:, cursor: }.compact
  sdk_get("/sdk/features", query)
end

#identify(external_id: nil, email: nil, name: nil, avatar_url: nil, platform: nil) ⇒ Object

POST /sdk/init — identify (find-or-create) an end-user. Returns the parsed body ({ "end_user_id" => ..., "project" => ... }).



36
37
38
# File 'lib/heedkit/client.rb', line 36

def identify(external_id: nil, email: nil, name: nil, avatar_url: nil, platform: nil)
  sdk_post("/sdk/init", external_id:, email:, name:, avatar_url:, platform:)
end

#roadmapObject

GET the public roadmap. Returns a HeedKit::Roadmap.



25
26
27
# File 'lib/heedkit/client.rb', line 25

def roadmap
  Roadmap.from_payload(get("/public/projects/#{project_key}/roadmap"))
end

#submit(end_user_id:, title:, description: nil, kind: "feature_request", tag: nil) ⇒ Object

POST /sdk/features — submit a feature on behalf of an end-user.



47
48
49
# File 'lib/heedkit/client.rb', line 47

def submit(end_user_id:, title:, description: nil, kind: "feature_request", tag: nil)
  sdk_post("/sdk/features", end_user_id:, title:, description:, kind:, tag:)
end

#vote(feature_id, end_user_id:) ⇒ Object

POST /sdk/features/:id/vote — toggle a vote.



52
53
54
# File 'lib/heedkit/client.rb', line 52

def vote(feature_id, end_user_id:)
  sdk_post("/sdk/features/#{feature_id}/vote", end_user_id:)
end