jobapis / jobs-jobs2careers

Easily integrate the Jobs2Careers API into your PHP application
https://www.jobapis.com/open-source/jobs2careers/
4 stars 3 forks source link

Use Jobs2Careers Provider with jobs-multi #8

Closed arbet closed 7 years ago

arbet commented 7 years ago

When I try to use the Jobs2careers provider class with jobs-multi, it doesn't work, although other providers do. I realize that it's part of the jobs-common repo, but not the jobs-multi.

Is there any easy way for me to add it? It just tells me that Provider J2c not found

CC: @karllhughes

karllhughes commented 7 years ago

@arbet thanks for reaching out. In order to use this package with Jobs Multi it needs to be upgraded to use version 2.0 of the jobs-common package. Unfortunately, I no longer have access to a Jobs2Careers API key, so I'm unable to upgrade and support this package.

I've reached out to Jobs2Careers a couple times, but my guess is they're not issuing new keys or they don't want to be part of this project. If you have any sway with them, I'd love to get a new key so I can upgrade this library and incorporate it into jobs-multi.

Until then, I'll leave this issue open for others' reference.

arbet commented 7 years ago

@karllhughes thanks for the clarification. I have reached out to them and will let you know if they're able to help.

If I am to upgrade the library myself, what steps would I need to take?

karllhughes commented 7 years ago

Thanks @arbet. It would actually be great if you could help me with the update. I can update the code and tests this week using my assumptions about the response (based on when I used to have a key) and then I can pass it over to you to manually test with your key. If you would just let me know if the updated version works or not, I could do a release without needing my own key.

I'll let you know when I have the updates ready in a branch.

arbet commented 7 years ago

Yes I can certainly help you with the testing. Also, if you need, I can issue you a temporary key from my account.

karllhughes commented 7 years ago

It would definitely help if I had a key, but I don't want you to get in any trouble for breaking J2C's terms of service, so that's up to you. I think I should be able to use the version 1 code and make it work if you don't mind helping me debug.

arbet commented 7 years ago

Ok fair enough, I'll be available for testing and if J2C allows me to give you a temporary key, I will let you know.

karllhughes commented 7 years ago

@arbet I've got a new branch called v2 that is updated to use the new version of jobs-common, which will then allow me to add this package to jobs-multi.

You can test it by making some queries (see the Readme file in the new branch) and running the tests with your API key:

$ ID=<YOUR PUBLISHER ID> PASS=<YOUR PUBLISHER PASSWORD> ./vendor/bin/phpunit

If you have any issues, you can mess around with the branch or just let me know. I'm pretty busy the rest of this week, but will likely have more time this weekend to clean anything up.

arbet commented 7 years ago

Thanks Karl, that was fast! Tried testing but composer is giving me headaches and cannot find the jobs2careers package. Here is how my composer file looks like. Am I missing something?

 {

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/jobapis/jobs-jobs2careers"
        }
    ],    
    "require": {
        "kamisama/php-resque-ex": "dev-master",
        "fresque/fresque": "~1.3.1",
        "textrazor/textrazor-php": "dev-master",
        "jobapis/jobs-multi": "^1.0",
        "jobapis/jobs-jobs2careers": "v2"
    },
    "require-dev": {
        "laravel/homestead": "^3.0"
    },
    "minimum-stability" : "dev",
    "prefer-stable" : true
}
karllhughes commented 7 years ago

Ah, the package is still under the old namespace in packagist. Try replacing "jobapis/jobs-jobs2careers": "v2" with "jobbrander/jobs-jobs2careers": "v2"

I'll switch the namespace when I release the new version.

Here it is on Packagist: https://packagist.org/packages/jobbrander/jobs-jobs2careers#v2.x-dev

arbet commented 7 years ago

I ran this command

./vendor/bin/phpunit vendor/jobbrander/jobs-jobs2careers/

and here is the output I got

PHPUnit 5.7.9 by Sebastian Bergmann and contributors.

EEEEE......... 14 / 14 (100%)

Time: 210 ms, Memory: 4.00MB

There were 5 errors:

1) JobApis\Jobs\Client\Test\J2cProviderTest::testItCanGetDefaultResponseFields Error: Class 'Mockery' not found

/home/vagrant/dev-freelancebooster-com/vendor/jobbrander/jobs-jobs2careers/tests/src/J2cProviderTest.php:15

2) JobApis\Jobs\Client\Test\J2cProviderTest::testItCanGetListingsPath Error: Class 'Mockery' not found

/home/vagrant/dev-freelancebooster-com/vendor/jobbrander/jobs-jobs2careers/tests/src/J2cProviderTest.php:15

3) JobApis\Jobs\Client\Test\J2cProviderTest::testItCanCreateJobObjectFromPayload Error: Class 'Mockery' not found

/home/vagrant/dev-freelancebooster-com/vendor/jobbrander/jobs-jobs2careers/tests/src/J2cProviderTest.php:15

4) JobApis\Jobs\Client\Test\J2cProviderTest::testItCanGetJobs Error: Class 'Mockery' not found

/home/vagrant/dev-freelancebooster-com/vendor/jobbrander/jobs-jobs2careers/tests/src/J2cProviderTest.php:15

5) JobApis\Jobs\Client\Test\J2cProviderTest::testItCanGetJobsFromApi Error: Class 'Mockery' not found

/home/vagrant/dev-freelancebooster-com/vendor/jobbrander/jobs-jobs2careers/tests/src/J2cProviderTest.php:15

ERRORS! Tests: 14, Assertions: 14, Errors: 5.

Note that I got the same output when I tried to run while adding the API Key and Pass

karllhughes commented 7 years ago

Sorry, I wasn't clear. If you clone the new branch of this repo then run composer install you should be able to run the test command: ID=<YOUR PUBLISHER ID> PASS=<YOUR PUBLISHER PASSWORD> ./vendor/bin/phpunit

If you include it in your project then try to run the tests it won't work because the dev-dependencies aren't installed.

arbet commented 7 years ago

Thanks for the clarification. Cloned, and ran the tests. I got valid results, but it didn't seem to connect to the API (test completed in a second or so). Here is the complete output

PHPUnit 4.8.34 by Sebastian Bergmann and contributors.

..............

Time: 1.12 seconds, Memory: 8.00MB

OK (14 tests, 26 assertions)

Generating code coverage report in Clover XML format ... done

Generating code coverage report in HTML format ... done

karllhughes commented 7 years ago

Sounds like it should be working then. You can do a couple things to verify:

Once we confirm its getting results I can start adding it to jobs-multi.

arbet commented 7 years ago

Here is a partial output of my var_dump:

Click to expand [1] = class JobApis\Jobs\Client\Job#1034 (33) { protected $company = string(13) "5892fea4935eb" protected $endDate = NULL protected $industry = string(13) "5892fea4937c4" protected $javascriptAction = string(7) "onclick" protected $javascriptFunction = string(13) "5892fea4935a6" protected $location = NULL protected $maximumSalary = NULL protected $minimumSalary = NULL protected $query = string(13) "5892fea48e059" protected $source = string(3) "J2c" protected $sourceId = string(13) "5892fea493779" protected $startDate = NULL protected $baseSalary = NULL protected $jobBenefits = NULL protected $datePosted = class DateTime#1066 (3) { ... } protected $educationRequirements = NULL protected $employmentType = NULL protected $experienceRequirements = NULL protected $hiringOrganization = class JobApis\Jobs\Client\Schema\Entity\Organization#1087 (8) { ... } protected $incentiveCompensation = NULL protected $jobLocation = class JobApis\Jobs\Client\Schema\Entity\Place#1088 (7) { ... } protected $occupationalCategory = NULL protected $qualifications = NULL protected $responsibilities = NULL protected $salaryCurrency = NULL protected $skills = NULL protected $specialCommitments = NULL protected $title = string(13) "5892fea493561" protected $workHours = NULL protected $alternateName = NULL protected $description = string(13) "5892fea4936df" protected $name = string(13) "5892fea493561" protected $url = NULL }


However, I tried to use the library in a test project. Dependencies are all met but I get the following error

PHP Fatal error: Uncaught Error: Class 'JobApis\Jobs\Client\Provider\J2cProvider' not found in /home/vagrant/testjobs2careers/test.php:11

Here is my test code


require_once('vendor/autoload.php');
$query = new JobApis\Jobs\Client\Queries\J2cQuery([
    'id' => 'MY_ID',
    'pass' => 'MY_API_KEY',
]);

$query->set('q', 'engineering');
$query->set('limit', 1);
// Instantiating an IndeedProvider with a query object
$client = new JobApis\Jobs\Client\Provider\J2cProvider($query);

// Get a Collection of Jobs
$jobs = $client->getJobs();

var_dump($jobs);

Here is my composer.json

 "require": {
        "jobbrander/jobs-jobs2careers": "v2.x-dev"
    }

I'm not sure this is an error on my side or a bug with the library.

karllhughes commented 7 years ago

First, it looks like you're dumping the dummy test data. To output the real one, put var_dump($results); right on line 128 of the provider test: https://github.com/jobapis/jobs-jobs2careers/blob/v2/tests/src/J2cProviderTest.php#L128

That will tell us if the library is actually connecting to the API.

Your second issue just looks like a typo.

This line: $client = new JobApis\Jobs\Client\Provider\J2cProvider($query);

Should be this: $client = new JobApis\Jobs\Client\Providers\J2cProvider($query); (note the "s" in Providers)

Looks like that typo is my fault though as that's what it says in the readme. I'll update that too.

Thanks again for helping me test this!

arbet commented 7 years ago

Ok, tests are fully working now and I get correct results.

As for the code above, I first got the error

PHP Fatal error: Uncaught JobApis\Jobs\Client\Exceptions\MissingParameterException: All Required parameters for this provider must be set in /home/vagrant/testjobs2careers/vendor/jobapis/jobs-common/src/Providers/AbstractProvider.php:112

I had to modify the J2cQuery.php file method userIp to add a dummy IP in place of null

Old Function

    protected function userIp()
    {
        return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
    }

New Function

    protected function userIp()
    {
        return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '172.154.143.2';
    }

Then it worked. I'm running this from CLI, so I'm not sure if it makes any difference. But other than that, seems to work.

karllhughes commented 7 years ago

@arbet we're getting close!

I've updated that function to use two methods for retrieving the IP address. The new one might work for command line runs like you did.

If it still doesn't work, a cleaner way to set your IP address is to set the ip in the query object:

$query = new JobApis\Jobs\Client\Queries\J2cQuery([
    'id' => YOUR_PUBLISHER_ID,
    'pass' => YOUR_PUBLISHER_PASSWORD,
    'ip' => '172.154.143.2',
]);

This will override the one that the code tries to auto-generate using the $_SERVER variable.

Once you confirm this works, I'll make a release, then start updating jobs-multi.

arbet commented 7 years ago

@karllhughes , your function is now working well without me needing to set the IP. Kindly let me know when the release and update are complete, thanks!

karllhughes commented 7 years ago

@arbet thanks so much for your help on this. I've released an update to this package (now available on packagist at jobapis/jobs-jobs2careers), and I've added this to the jobs-multi package: https://github.com/jobapis/jobs-multi/releases/tag/1.1.0

I'm closing this issue, but if you encounter any other problems with this package, open up a new one and let me know. Thanks!

arbet commented 7 years ago

Karl, thank you very much. If you need a LinkedIn recommendation or a video testimonial, let me know. I'd be happy to help.

karllhughes commented 7 years ago

@arbet I actually am curious how you'll be using the project and if it's for a company or just a side project. If you'd rather not post it publicly, feel free to email me: khughes.me@gmail.com

I just like knowing how people are using the libraries so I can better decide what to build next.

Thanks again!

arbet commented 7 years ago

Just sent you an email!

vrwired commented 6 years ago

I ran into same issue needing to pluralize provider and correct it to $client = new JobApis\Jobs\Client\Providers\ [service-provider] ... in my case I was following the README example at https://github.com/jobapis/jobs-usajobs