<commit_before>module EasyPost
  class ParcelLocker
    attr_reader :id, :_links, :type, :services, :payment_type, :address, :status,
                :address_str, :location, :location_description

    def initialize(attributes)
      @id = attributes['id']
      @_links = attributes['_links']
      @type = attributes['type']
      @services = attributes['services']
      @payment_type = attributes['payment_type']
      @address = attributes['address']
      @status = attributes['status']
      @address_str = attributes['address_str']
      @location = attributes['location']
      @location_description = attributes['location_description']
    end

    def self.all
      # @review: handle of timeouts, wrong response codes
      response = Faraday.get(API_URL)
      JSON::Validator.validate!(SCHEMA, response.body)
      # @review: to be more loosely coupled it could be hash or openstruct
      JSON.parse(response.body)['_embedded']['machines'].collect { |attr| ParcelLocker.new(attr) }
    end

    def self.find(id)
      all[all.index { |parcel_locker| parcel_locker.id == id }]
    end
  end
end<commit_msg>.find for not found case<commit_after>module EasyPost
  class ParcelLocker
    attr_reader :id, :_links, :type, :services, :payment_type, :address, :status,
                :address_str, :location, :location_description

    def initialize(attributes)
      @id = attributes['id']
      @_links = attributes['_links']
      @type = attributes['type']
      @services = attributes['services']
      @payment_type = attributes['payment_type']
      @address = attributes['address']
      @status = attributes['status']
      @address_str = attributes['address_str']
      @location = attributes['location']
      @location_description = attributes['location_description']
    end

    def self.all
      # @review: handle of timeouts, wrong response codes
      response = Faraday.get(API_URL)
      JSON::Validator.validate!(SCHEMA, response.body)
      # @review: to be more loosely coupled it could be hash or openstruct
      JSON.parse(response.body)['_embedded']['machines'].collect { |attr| ParcelLocker.new(attr) }
    end

    def self.find(id)
      # @review: if we want to have kind of ActiveRecord style, then we can raise some kind of NotFoundError
      all.find { |parcel_locker| parcel_locker.id == id }
    end
  end
end
{'fraction_non_alphanumeric': 0.11747243426632739, 'fraction_numerical': 0.0, 'mean_word_length': 3.4258911819887428, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3926603', 'n_tokens_mistral': 687, 'n_tokens_neox': 666, 'n_words': 173}