Error when pushing Ruby gem (credentials "not found") - ruby

When running gem push "example.gem", I get asked to put my GitHub username and password, instead of rubygems.org.
I've put my credentials for BOTH and I know they are correct, but I keep on getting them rejected with a "Not Found" response.
Anyone knows the solution? Here's part of my gemspec file if that helps:
Gem::Specification.new do |spec|
spec.name = "gemname"
spec.version = GEMNAME::VERSION
spec.authors = ["author"]
spec.email = ["author#gmail.com"]
spec.summary = "Example Gem"
spec.description = "Example Gem"
spec.homepage = "http://rubygems.org/gems/examplegem"
spec.license = "MIT"
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
spec.metadata["allowed_push_host"] = "https://rubygems.org/profiles/username"
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://rubygems.org/profiles/username"

Related

Sample ''Hola'" Rubygem push error on windows

I am following the very basic tutorial found here: http://guides.rubygems.org/make-your-own-gem/
hola_username.rb:
class Hola
def self.hi
puts "Hello world!"
end
end
hola_username.gemspec:
Gem::Specification.new do |s|
s.name = 'hola_username'
s.version = '0.0.0'
s.date = '2010-04-28'
s.summary = "Hola!"
s.description = "A simple hello world gem"
s.authors = ["Surname Lastname"]
s.email = 'me.me#gmail.com'
s.files = ["lib/hola_username.rb"]
s.homepage =
'http://rubygems.org/gems/hola_username'
s.license = 'MIT'
end
That really is all there is to the project.
I can build my gem with
gem build .\hola_username.gemspec
I have also tested it by importing and executing the hi function of the Hola class and it works:
PS E:\hola_username> gem install .\hola_username-0.0.0.gem
Successfully installed hola_username-0.0.0
Parsing documentation for hola_username-0.0.0
Done installing documentation for hola_username after 0 seconds
1 gem installed
&
irb(main):001:0> require 'hola_username'
=> true
irb(main):002:0> Hola.hi
Hello world!
=> nil
irb(main):003:0>
But when I try to
gem push .\hola_username-0.0.0.gem
I get:
ERROR: While executing gem ... (Psych::SyntaxError)
(): control characters are not allowed at line 1 column 1
Any ideas?
Edit: I am on a windows 10 machine using ruby 2.0.0p598
Edit v01: Anything I put after gem push will result in the above error, doesn't seem to be a problem with the sample rubygem.
Edit v02: My credentials file that was generated in the .gem folder however stars with hex characters: fffe2d002d00.. Which might be the ones causing trouble?
My credentials file in .gem folder was encoded with UCS2 - Little Endian and converting it to UTF without BOM did the trick.
Although I have absolutey no idea why..

While building a gem i get an error: "No implicit conversion of String into Integer"

I am new to programming in Ruby. I was following the example of creating a new gem. But when I issue the command to build the gem (gem build packagename.spec), I am getting an error.
Here is my code snippet:
Gem::Specification.new do |s|
s.name = "moviesAndPlaylists"
s.version = "1.0.0"
s.author = "Chetan Yewale"
s.email = "yewalechetan#gmail.com"
s.summary = "Plays and reviews movies"
s.description = File.read(File.join(File.dirname(__FILE__)), 'README')
s.homepage = "http://github.com/"
s.files = Dir["{bin, lib, spec}/**/*"] + %w(LICENSE README)
s.test_files = Dir["spec/**/*"]
s.executables = [ 'moviesAndPlaylists' ]
s.required_ruby_version = '>=1.9'
s.add_development_dependecy 'rspec'
end
Please let me know what is wrong? Why do I get an error message like:
Invalid gemspec in [moviesAndPlaylists.gemspec]: no implicit conversion of String into Integer
ERROR: Error loading gemspec. Aborting.
I tried commenting out some lines and starting again, but could not figure it out. If anybody has encountered this error before, please let me know,
Just change the line
s.executables = [ 'moviesAndPlaylists' ]
to
s.executables << 'moviesAndPlaylists'
Look the documentation of executables.

Accessing text file in ruby gem

I am using ruby version 2.0.0 , I made some custom logo in text file named logo.txt like this:
_____
| |
|_____|
|
|
|
Now i made a gem with name of "custom" and placed this file under lib/logo.txt . Now i wants to print this file in my script under ruby gem so i wrote in this way.
file = File.open("lib/logo.txt")
contents = file.read
puts "#{contents}"
But above code produce errors, like:
/usr/local/rvm/rubies/ruby-2.0.0-p451/lib/ruby/gems/2.0.0/gems/custom-0.0.1/lib/custom/custom.rb:1551:in `initialize': No such file or directory - lib/logo.txt (Errno::ENOENT)
I include this logo.txt file in gemspec as per below:
Gem::Specification.new do |s|
s.name = "custom"
s.version = VERSION
s.author = "Custom Wear"
s.email = "custom#custom.com"
s.homepage = "http://custom.com"
s.summary = "custom wera"
s.description = File.read(File.join(File.dirname(__FILE__), 'README'))
s.license = 'ALL RIGHTS RESERVED'
s.files = [""lib/custom.rb", "lib/custom/custom.rb", "lib/custom /version.rb","lib/logo.txt"]
s.test_files = Dir["spec/**/*"]
s.executables = [ 'custom' ]
s.require_paths << 'lib/'
The file is opened relative to the current working directory, unless you specify the full path.
In order to avoid hard-coding full paths, you can get the full path of the current file from Ruby using __FILE__. In fact you can see in the custom.gemspec file something very similar going on:
File.join( File.dirname(__FILE__), 'README')
I think you can get to your logo file like this:
logo_path = File.join( File.dirname(__FILE__), '../logo.txt' )
file = File.open( logo_path )
In Ruby 2.0, you also have __dir__ (which can replace File.dirname(__FILE__)) but that would not be compatible with Ruby 1.9. Generally you are safer using backward-compatible syntax in gems in case you are not sure what someone has when they run your library.

Unable to activate faraday_middleware-0.9.0 // Gem::LoadError // trying to run the pocket-ruby gem

I am trying to run the pocket-ruby gem and after I clone the repo and bundle, it raises this error:
Unable to activate faraday_middleware-0.9.0, because faraday-0.9.0 conflicts with faraday
(< 0.9, >= 0.7.4)
The gemspecfile for the pocket-ruby gem looks like this:
require File.expand_path('../lib/pocket/version', __FILE__)
Gem::Specification.new do |s|
s.add_development_dependency('sinatra', '~> 1.3.3')
s.add_development_dependency('multi_xml')
s.add_runtime_dependency('faraday', ['>= 0.7', '< 0.9'])
s.add_runtime_dependency('faraday_middleware', '~> 0.8')
s.add_runtime_dependency('multi_json', '>= 1.0.3', '~> 1.0')
s.add_runtime_dependency('hashie', '>= 0.4.0')
s.authors = ["Turadg Aleahmad","Jason Ng PT"]
s.description = %q{A Ruby wrapper for the Pocket API v3 (Add, Modify and Retrieve)}
s.email = ['turadg#aleahmad.net',"me#jasonngpt.com"]
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.files = `git ls-files`.split("\n")
s.homepage = 'https://github.com/turadg/pocket-ruby'
s.name = 'pocket-ruby'
s.platform = Gem::Platform::RUBY
s.require_paths = ['lib']
s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
if s.respond_to? :required_rubygems_version=
s.rubyforge_project = s.name
s.summary = %q{Ruby wrapper for the Pocket API v3}
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.version = Pocket::VERSION
end
I messed around with changing the versions on the two dependencies in question but didn't have any luck, since I guess I am not entirely sure what the error is saying. Thoughts?
There's a conflict between the two version specifiers - ~> 0.8 means "any version of the form 0.x", but < 0.9 means that 0.9 is not actually allowed.
You'll need to determine which of these need to change - maybe ~> 0.8 should really be ~> 0.8.0, which would specify "any version of the form 0.8.x".
More info on the pessimistic constraint operator (~>) here:
Meaning of tilde-greater-than (~>) in version requirement?

Blank output using Ruby twitter gem

When I execute there is no error, no output either. This is all the code in the file.
require 'twitter'
client = Twitter::REST::Client.new do |config|
config.consumer_key = ""
config.consumer_secret = ""
config.access_token = ""
config.access_token_secret = ""
end
client.home_timeline
When I use this example it works, so I assume I have something right:
topics = ["coffee", "tea"]
client.filter(:track => topics.join(",")) do |object|
puts object.text if object.is_a?(Twitter::Tweet)
end
This is the only example I can get working, all others with produce no output. No errors.
Try using "$client" that will make it global. May work this way.
$client = Twitter::REST::Client.new do |config|
config.consumer_key = ""
config.consumer_secret = ""
config.access_token = ""
config.access_token_secret = ""
end
$client.home_timeline

Resources