class Zendesk2::Mock

Attributes

jwt_token[R]
last_request[RW]
token[R]
url[R]
username[R]

Public Class Methods

data() click to toggle source

rubocop:disable Metrics/BlockLength

# File lib/zendesk2/mock.rb, line 7
def self.data
  @data ||= Hash.new do |h, k|
    h[k] = {
      brands: {},
      categories: {},
      forums: {},
      groups: {},
      help_center_access_policies: {},
      help_center_articles: {},
      help_center_categories: {},
      help_center_posts: {},
      help_center_sections: {},
      help_center_subscriptions: {},
      help_center_topics: {},
      help_center_translations: {},
      identities: {},
      memberships: {},
      organizations: {},
      ticket_audits: {},
      ticket_comments: {},
      ticket_fields: {},
      ticket_forms: {},
      ticket_metrics: {},
      tickets: {},
      topic_comments: {},
      topics: {},
      user_fields: {},
      users: {},
      views: {},
    }
  end
end
new(options = {}) click to toggle source
# File lib/zendesk2/mock.rb, line 62
def initialize(options = {})
  @url                 = options[:url]
  @path                = URI.parse(url).path
  @username = options[:username]
  @password = options[:password]
  @token               = options[:token]
  @jwt_token           = options[:jwt_token]

  @current_user ||= data[:users].values.find do |u|
    @username == u['name']
  end || create_user(
    'user' => { 'email' => @username, 'name' => @username }
  ).body['user']

  @current_user_identity ||= data[:identities].values.first
end
reset() click to toggle source
# File lib/zendesk2/mock.rb, line 54
def self.reset
  data.clear
end
serial_id() click to toggle source
# File lib/zendesk2/mock.rb, line 40
def self.serial_id
  @current_id ||= 0
  @current_id += 1
  @current_id
end

Public Instance Methods

current_user() click to toggle source

Lazily re-seeds data after reset @return [Hash] current user response

# File lib/zendesk2/mock.rb, line 81
def current_user
  data[:users][@current_user['id']]               ||= @current_user
  data[:identities][@current_user_identity['id']] ||= @current_user_identity

  @current_user
end
data() click to toggle source
# File lib/zendesk2/mock.rb, line 46
def data
  self.class.data[@url]
end
reset() click to toggle source
# File lib/zendesk2/mock.rb, line 50
def reset
  data.clear
end
serial_id() click to toggle source
# File lib/zendesk2/mock.rb, line 58
def serial_id
  self.class.serial_id
end