Giter Site home page Giter Site logo

Problems with the example about her HOT 13 CLOSED

remi avatar remi commented on August 20, 2024
Problems with the example

from her.

Comments (13)

tdtadeu avatar tdtadeu commented on August 20, 2024 5

I know this is an old thread, but I ran into this same problem just now and thought it'd be useful to warn other people to double check a missing http:// in the beginning of the url.
That solved it for me. 😉

from her.

calmyournerves avatar calmyournerves commented on August 20, 2024

I guess the problem is here:

connection.use Faraday::BasicAuthentication.basic_auth("user","pass")

Can you try using it like this?

# config/initializers/her.rb
Her::API.setup :url => "http://127.0.0.1:3003/api/v1/" do |connection|
  connection.use Faraday::Request::BasicAuthentication "user", "pass"
  connection.use Faraday::Request::UrlEncoded
  connection.use Her::Middleware::DefaultParseJSON
  connection.use Faraday::Adapter::NetHttp
end

from her.

ceicke avatar ceicke commented on August 20, 2024

No, that wasn't the problem. I even tried it out without any authentication in there hoping to run in a 403.

from her.

remi avatar remi commented on August 20, 2024

@ceicke I have not been able to reproduce the error… Did you find a fix for it or are you still experiencing the issue?

from her.

ceicke avatar ceicke commented on August 20, 2024

I wasn't able to resolve the problem and have therefore moved on to implementing the REST interface that I connect to with pure HTTP calls. I think you can close this issue and wait if it comes up again. I was implementing "her" in a really complicated project, so maybe there were some side effects from other Gems etc.

from her.

teamon avatar teamon commented on August 20, 2024

I have the same issue, and I know why.

class A::B::C
  include Her::Model
end

C.find(1) produces path like "a::b::c/1"

from her.

remi avatar remi commented on August 20, 2024

@teamon Do you know why?

If I run the following code:

def stub_api_for(klass)
  klass.uses_api (api = Her::API.new)

  # Here, you would customize this for your own API (URL, middleware, etc)
  # like you have done in your application’s initializer
  api.setup :url => "https://api.example.com" do |connection|
    connection.use Her::Middleware::DefaultParseJSON
    connection.adapter(:test) { |s| yield(s) }
  end
end

module A
  module B
  end
end

class A::B::C
  include Her::Model
end

stub_api_for(A::B::C) do |stub|
  stub.get("/cs/1") do |env|
    [200, {}, { :id => 1, :foo => "bar"}.to_json]
  end
end

p A::B::C.find(1)

I get this output:

#<A::B::C(cs/1) id=1 foo="bar">

from her.

teamon avatar teamon commented on August 20, 2024

I was referencing older version of her (0.2.x), 0.4.1 resolved that issue (not sure if exactly 0.4.1, but 0.4.1 works for me)

from her.

brissmyr avatar brissmyr commented on August 20, 2024

I got the same error but eventually got it working. It turned out that I was missing a "http://" in Her::API.setup(url: "http://mysite.com/api")

from her.

billc avatar billc commented on August 20, 2024

I received the same error and determine from the source I needed to call the header method to set user, pass.

c.use Faraday::Request::BasicAuthentication.header user, password

from her.

nickweavers avatar nickweavers commented on August 20, 2024

I am not able to get basic authentication working,. Here's what I have tried:

Her::API.setup :url => "https://my.favourite_api.org" do |connection|

Authentication

connection.use Faraday::Request::BasicAuthentication "itsme", "letmein"

The RubyMine debugger tells me:

Uncaught exception: undefined method `BasicAuthentication' for Faraday::Request:Class

Can anyone help?

from her.

nickweavers avatar nickweavers commented on August 20, 2024

It was simply a missing comma:
connection.use Faraday::Request::BasicAuthentication, "itsme", "letmein"

from her.

jhirbour avatar jhirbour commented on August 20, 2024

@nickweavers comment works for me. I added a PR to the readme.

from her.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.