• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sue445 / pixela / #12148

26 Dec 2025 11:22AM UTC coverage: 44.444% (-53.8%) from 98.195%
#12148

push

web-flow
Merge b4c2c510f into 6f2b98fd6

120 of 270 relevant lines covered (44.44%)

0.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.0
/lib/pixela/client.rb
1
module Pixela
1✔
2
  class Client
1✔
3
    autoload :GraphMethods,        "pixela/client/graph_methods"
1✔
4
    autoload :PixelMethods,        "pixela/client/pixel_methods"
1✔
5
    autoload :ProfileMethods,      "pixela/client/profile_methods"
1✔
6
    autoload :UserMethods,         "pixela/client/user_methods"
1✔
7
    autoload :WebhookMethods,      "pixela/client/webhook_methods"
1✔
8

9
    include GraphMethods
1✔
10
    include PixelMethods
1✔
11
    include ProfileMethods
1✔
12
    include UserMethods
1✔
13
    include WebhookMethods
1✔
14

15
    API_ENDPOINT = "https://pixe.la/v1"
1✔
16
    TOP_ENDPOINT = "https://pixe.la"
1✔
17

18
    # @!attribute [r] username
19
    # @return [String]
20
    attr_reader :username
1✔
21

22
    # @param username [String]
23
    # @param token [String] secret token
24
    def initialize(username:, token:)
1✔
25
      @username = username
×
26
      @token    = token
×
27
    end
28

29
    # @return [String]
30
    def inspect
1✔
31
      # NOTE: hide @token
32
      %Q(#<Pixela::Client:0x#{"%016X" % object_id} @username="#{username}">)
×
33
    end
34

35
    # @param graph_id [String]
36
    #
37
    # @return [Pixela::Graph]
38
    def graph(graph_id)
1✔
39
      Graph.new(client: self, graph_id: graph_id)
×
40
    end
41

42
    # @param webhook_hash [String]
43
    #
44
    # @return [Pixela::Webhook]
45
    def webhook(webhook_hash)
1✔
46
      Webhook.new(client: self, webhook_hash: webhook_hash)
×
47
    end
48

49
    private
1✔
50

51
    # @!attribute [r] token
52
    # @return [String]
53
    attr_reader :token
1✔
54

55
    # @param request_headers [Hash]
56
    #
57
    # @return [Faraday::Connection]
58
    def connection(request_headers: user_token_headers, endpoint: API_ENDPOINT)
1✔
59
      Faraday.new(url: endpoint, headers: request_headers) do |conn|
×
60
        conn.request :json
×
61
        conn.response :mashify, mash_class: Pixela::Response
×
62
        conn.response :json
×
63
        conn.response :raise_error
×
64

65
        if Pixela.config.debug_logger
×
66
          conn.request :curl, Pixela.config.debug_logger, :debug
×
67
          conn.response :logger, Pixela.config.debug_logger
×
68
        end
69

70
        conn.adapter Faraday.default_adapter
×
71
      end
72
    end
73

74
    def with_error_handling
1✔
75
      yield
×
76
    rescue Faraday::ClientError, Faraday::ServerError => error
77
      begin
78
        body = JSON.parse(error.response[:body])
×
79
        raise PixelaError, body["message"]
×
80
      rescue JSON::ParserError
81
        raise error
×
82
      end
83
    end
84

85
    def default_headers
1✔
86
      {
87
        "User-Agent" => "Pixela v#{Pixela::VERSION} (https://github.com/sue445/pixela)",
×
88
        "Content-Type" => "application/json",
89
      }
90
    end
91

92
    def user_token_headers
1✔
93
      { "X-USER-TOKEN" => token }.merge(default_headers)
×
94
    end
95

96
    def to_boolean_string(flag)
1✔
97
      flag ? "yes" : "no"
×
98
    end
99

100
    def to_ymd(date)
1✔
101
      return nil unless date
×
102

103
      date.strftime("%Y%m%d")
×
104
    end
105
  end
106
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc