Sha256: 9d0fef98e3ba42dd3faabee3d53f670e5306cc7c0be53ed16f1acab605c265f8

Contents?: true

Size: 1.14 KB

Versions: 15

Compression:

Stored size: 1.14 KB

Contents

require 'securerandom'
class Ey::Core::Client
  class Real
    def create_user(params={})
      request(
        :method => :post,
        :path   => "/users",
        :body   => params,
      )
    end
  end # Real

  class Mock
    def create_user(params={})
      if self.authentication != :hmac
        response(status: 403)
      end

      if self.data[:users].map{ |_, user| user["email"] }.include?(params["user"]["email"])
        response(
          :status => 422,
          :body => {
            :errors => ["Email has already been taken"]
          }
        )
      end

      resource_id = self.uuid

      resource = params["user"].dup
      resource["token"] = SecureRandom.hex(20)

      resource.merge!({
        "id"          => resource_id,
        "accounts"    => url_for("/users/#{resource_id}/accounts"),
        "memberships" => url_for("/users/#{resource_id}/memberships"),
        "keypairs"    => url_for("/users/#{resource_id}/keypairs"),
      })

      self.data[:users][resource_id] = resource

      response(
        :body    => {"user" => resource},
        :status  => 201,
      )
    end
  end # Mock
end # Ey::Core::Client

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ey-pro-cli-0.0.17 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.16 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.15 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.14 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.13 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.12 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.11 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.10 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.9 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.8 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.7 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.6 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.5 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.4 lib/vendor/core/ey-core/requests/create_user.rb
ey-pro-cli-0.0.3 lib/vendor/core/ey-core/requests/create_user.rb